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