A
Anonymous
Guest
The code below does not display an image it simply puts a load of hieroglyphic on the screen as if its the bytes of data, but not formatted as a picture.
Initially it was a simple straight code with out it being a function and it works, but in the function it does not, any help greatly appreciated.
GY
Initially it was a simple straight code with out it being a function and it works, but in the function it does not, any help greatly appreciated.
GY
Code:
<?php
function show_resized_image($filepath){
echo $filepath,"??";
/*
* PHP GD
* resize an image using GD library
*/
// File and new size
//the original image has 800x600
//$filepath='images/fam3-3.JPG';
//the resize will be a percent of the original size
$percent = 0.25;
// Get new sizes
list($width, $height) = getimagesize($filepath);
$newwidth = $width * $percent;
$newheight = $height * $percent;
// Content type
header('Content-Type: image/jpeg');
// Load
$thumb = imagecreatetruecolor($newwidth, $newheight);
$source = imagecreatefromjpeg($filepath);
// Resize
imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
// Output and free memory
//the resized image will be 400x300
imagejpeg($thumb);
imagedestroy($thumb);
return;
}
$user_name = "root";
$password = "";
$database = "photos";
$server = "localhost";
$photoid= 55;
$SQL = "SELECT * FROM photosdata where ID=$photoid";
$db_handle = mysqli_connect($server, $user_name, $password,$database);
$result = mysqli_query($db_handle,$SQL);
$db_field=mysqli_fetch_assoc($result);
$fname=$db_field['photoname'];
$path=$db_field['path'];
//echo $path.$fname;
/*
echo $path.$match["photoname"];
echo '<img src="'.$path.$match["photoname"].'" />';
mysqli_close($db_handle);
*/
$this_file=$path.$fname;
$target=show_resized_image('$this_file');
//$target=show_resized_image('images/fam3-3.JPG');
?>