refiking Posted August 12, 2009 Share Posted August 12, 2009 I have a function that works for jpg. I want it to do the same exact thing for gif and png, but I am failing at it currently and am not sure why. Can you tell me what is wrong with my modifications? Original Functioning Code function easyResize($img_sourse, $save_to, $quality, $width) { $size = GetImageSize($img_sourse); $im_in = ImageCreateFromJPEG($img_sourse); $new_height = ($width * $size[1]) / $size[0]; // Generate new height for image $im_out = imagecreatetruecolor($width, $new_height); fastimagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $width, $new_height, $size[0], $size[1]); ImageJPEG($im_out, $save_to, 100); // Create image ImageDestroy($im_in); ImageDestroy($im_out); } Modified Nonworking Code function easyResize($img_sourse, $save_to, $quality, $width) { $size = GetImageSize($img_sourse); $pos = strpos($img_sourse, 'jpg'); IF ($pos !== false){ $im_in = ImageCreateFromJPEG($img_sourse); } $pos2 = strpos($img_sourse, 'gif'); IF ($pos2 !== false){ $im_in = imagecreatefromgif($img_sourse); } $pos3 = strpos($img_sourse, 'png'); IF ($pos3 !== false){ $im_in = imagecreatefrompng($img_sourse); } $new_height = ($width * $size[1]) / $size[0]; // Generate new height for image $im_out = imagecreatetruecolor($width, $new_height); fastimagecopyresampled($im_out, $im_in, 0, 0, 0, 0, $width, $new_height, $size[0], $size[1]); echo $img_sourse . '<br>' . $im_in . '<br>' . $im_out; exit; IF ($pos !== false){ ImageJPEG($im_out, $save_to, 100); // Create image } IF ($pos2 !== false){ imagegif($im_out, $save_to); } IF ($pos3 !== false){ imagepng($im_out, $save_to); } ImageDestroy($im_in); ImageDestroy($im_out); } Link to comment https://forums.phpfreaks.com/topic/169964-expanding-a-image-function/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.