Jump to content


Photo

resizing my images only works for JPG ?


  • Please log in to reply
3 replies to this topic

#1 jasonc

jasonc
  • Members
  • PipPipPip
  • Advanced Member
  • 841 posts

Posted 27 June 2006 - 05:56 AM

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

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 27 June 2006 - 06:12 AM

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.

#3 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 27 June 2006 - 06:22 AM

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]

#4 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 27 June 2006 - 11:47 AM

Might try here...

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

Lite...

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users