Jump to content

resizing my images only works for JPG ?


jasonc

Recommended Posts

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;
}
?>
Link to comment
https://forums.phpfreaks.com/topic/12996-resizing-my-images-only-works-for-jpg/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.