Forum Moderators: coopster
I did a script that generates a thumb of the normal image( is not well a thumb, why the image is great ), but the matter is that I catch the image size, I multiply by 70 and divide for 100 to generate an image a little smaller of the original. That I happens wanted this image was generated with a maximum size.
Example: If I have an image with 1536px and do that process, she stays with 1075px. But I wanted her to get at most with 500px. How Could I do that?( If I decrease the 70 the smaller images stay very small )
Thanks
$im_file_name = "../path_to_image/".$_FILES['image_file']['name'];
$image_attribs = getimagesize($im_file_name);
$im_old = imageCreateFromJpeg($im_file_name);
$th_max_width=100; //give your dimension
$th_max_height=75; //give your dimension
$ratio = ($width > $height)? $th_max_width/$image_attribs[0] : $th_max_height/$image_attribs[1];
$th_width = $image_attribs[0] * $ratio;
$th_height = $image_attribs[1] * $ratio;
$im_new = imagecreatetruecolor($th_width,$th_height);
$th_file_name = "../new_path_to_image/some_folder/". $_FILES['image_file']['name'];
imageCopyResampled($im_new,$im_old,0,0,0,0,$th_width,$th_height, $image_attribs[0], $image_attribs[1]);
imageJpeg($im_new,$th_file_name,100);
The above script will create a thumb from an uploaded image. Play around with it and adjust it to your neds