PDA

View Full Version : Dynamically Resizing Images.



JBottero
07-29-2008, 07:20 AM
I use something like this to resize dynamically images. Is there a way to wrap this in a function and class that when called returns the image object?

<?
$src_img = imagecreatefromjpeg('./path/to/image.jpg');
$srcsize = getimagesize('./path/to/image.jpg');
$dest_x = 200;
$dest_y = (200 / $srcsize[0]) * $srcsize[1];
$dst_img = imagecreatetruecolor($dest_x, $dest_y);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_x, $dest_y, $srcsize[0], $srcsize[1]);
header("content-type: image/jpeg");
imagejpeg($dst_img);
imagedestroy($src_img);
imagedestroy($dst_img);
?>
For exacmple, right now I could use it to dynamically resize images by having it inline in the HTML:

<img src="./image_script.php?img=image_name.jpg">
But if it could be wrapped in a class / function, it could be done without exposing the script to possible exploitation maybe...

I'd like to avoid resizing the image and dumping it in a temp directory. That could get huge.

motormichael12
07-30-2008, 01:21 AM
As it only uses gd functions I don't see a way ti could be exploited