Majik: Thanks for that code. I am trying to alter it so as to call it from a web page. Do you see any problems with this:
$filename = $HTTP_GET_VARS['mls'];
if(file_exists("/home/user/public_html/photos/" . $filename . ".jpg")) {
$src_file = "/home/user/public_html/photos/" . $filename . ".jpg";
} else {
$src_file = "/home/user/public_html/assets/nophoto.jpg";
}
$dest_file = "thumb.jpg";
$thumbw = 120;
$thumbh = 92;
$quality = 75;
$src_img = imagecreatefromjpeg($src_file);
$dst_img = image_resize($src_img, $thumbw, $thumbh);
header("Content-type: image/jpeg");
imagejpeg($dst_img, $dest_file, $quality);
imagedestroy($src_img);
imagedestroy($dst_img);
// resize original
function image_resize($im, $maxWidth, $maxHeight) {
$maxAspect = $maxWidth / $maxHeight; //Figure out the aspect ratio of the desired limits
$origWidth = imagesx($im); //Get the width of the uploaded image
$origHeight = imagesy($im); //Get the height of the uploaded image
$origAspect = $origWidth / $origHeight; //Get the aspect ratio of the uploaded image
if (($origWidth > $maxWidth) || ($origHeight > $maxHeight)) { //See if we actually need to do anything
if ($origAspect <= $maxAspect) { //If the aspect ratio of the uploaded image is less than or equal to the target size...
$newWidth = $maxHeight * $origAspect; //Resize the image based on the height
$newHeight = $maxHeight;
} else { //If the ratio is greater...
$newWidth = $maxWidth; //Resize based on width
$newHeight = $maxWidth / $origAspect;
}
$om = imagecreatetruecolor($newWidth, $newHeight); //Create the target image
imagecopyresampled($om, $im, 0, 0, 0, 0, $newWidth, $newHeight, $origWidth, $origHeight); //actually do the resizing
return($om); //Return the result
} else {
return($im); //Or don't do anything and just return the input.
}
}
Then call it with : <img src="createthumb.php?filename=80">
There are no errors - but the image does not display??