Jump to content
Updating IPB tonight Read more... ×

Archived

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

jasonc

resizing my images only works for JPG ?

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;
}
?>

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
Might try here...

[a href=\"http://www.nstoia.com/toh/technical/imageresize/\" target=\"_blank\"]http://www.nstoia.com/toh/technical/imageresize/[/a]

Lite...

Share this post


Link to post
Share on other sites

×

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.