Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.