Jump to content

How to save generated image


achintha

Recommended Posts

I found image resizing code. But it's only showing the resized image. But I want to save it to server.how can I do that?

 

   1. <?php
   2. header('Content-type: image/jpeg');
   3. //$myimage = resizeImage('filename', 'newwidthmax', 'newheightmax');
   4. $myimage = resizeImage('test.jpg', '150', '120');
   5. print $myimage;
   6.  
   7. function resizeImage($filename, $newwidth, $newheight){
   8.     list($width, $height) = getimagesize($filename);
   9.     if($width > $height && $newheight < $height){
  10.         $newheight = $height / ($width / $newwidth);
  11.     } else if ($width < $height && $newwidth < $width) {
  12.         $newwidth = $width / ($height / $newheight);  
  13.     } else {
  14.         $newwidth = $width;
  15.         $newheight = $height;
  16.     }
  17.     $thumb = imagecreatetruecolor($newwidth, $newheight);
  18.     $source = imagecreatefromjpeg($filename);
  19.     imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  20.     return imagejpeg($thumb);
  21. }
  22. ?>

Link to comment
https://forums.phpfreaks.com/topic/126428-how-to-save-generated-image/
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.