Jump to content

Dynamically Resizing Images "on the fly"


Arty Ziff

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/117120-dynamically-resizing-images-on-the-fly/
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.