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