jasonc Posted June 27, 2006 Share Posted June 27, 2006 I have the following code that seems to only work for JPG files.I would really like to allow visitors to upload any type of file, but i still need to have the option to resize them if they are to big. (more than 500x500)I have just looked at my code and seen that it will only resize a JPG file anyway. (imagecreatefromjpeg)Is there a standard PHP resize function that can resize any image?Thank you in advance for your help.<?function resize_jpeg_image($src_image, $dst_image, $max_width, $max_height){ if (!($src_img = imagecreatefromjpeg($src_image))) return 0; if (imagesx($src_img) > $max_width || imagesy($src_img) > $max_height) { $origwidth = imagesx($src_img); $origheight = imagesy($src_img); if ($max_height / $origheight < $max_width / $origwidth) { $scale = $max_height / $origheight; } if ($max_width / $origwidth < $max_height / $origheight) { $scale = $max_width / $origwidth; } $height = $scale * $origheight; $width = $scale * $origwidth; if (!($dst_img = imagecreatetruecolor($width, $height)) || !imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $origwidth, $origheight) || !imagejpeg($dst_img, $dst_image ) || !imagedestroy($dst_img)) return 0; } else if (!copy($src_image, $dst_image)) return 0; return 1;}?> Quote Link to comment https://forums.phpfreaks.com/topic/12996-resizing-my-images-only-works-for-jpg/ Share on other sites More sharing options...
trq Posted June 27, 2006 Share Posted June 27, 2006 There is no standard, and there is lots of different functionality and compile options due to licensing issues, maye the manual (http://php.net/gd) will help you out. Quote Link to comment https://forums.phpfreaks.com/topic/12996-resizing-my-images-only-works-for-jpg/#findComment-49969 Share on other sites More sharing options...
Michael4172 Posted June 27, 2006 Share Posted June 27, 2006 You can get a function at the below link. I believe if you change the content type to whatever image format you have (.gif / .bmp) it would work[a href=\"http://uk.php.net/imagecopyresized\" target=\"_blank\"]PHP Manual - imagecopyresized[/a] Quote Link to comment https://forums.phpfreaks.com/topic/12996-resizing-my-images-only-works-for-jpg/#findComment-49972 Share on other sites More sharing options...
litebearer Posted June 27, 2006 Share Posted June 27, 2006 Might try here...[a href=\"http://www.nstoia.com/toh/technical/imageresize/\" target=\"_blank\"]http://www.nstoia.com/toh/technical/imageresize/[/a]Lite... Quote Link to comment https://forums.phpfreaks.com/topic/12996-resizing-my-images-only-works-for-jpg/#findComment-50047 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.