The essence of the question is: I upload a picture to the server, save it for example at $uploadfile='im/20130623134413_2266.jpg'; then I need to reduce this picture, do not make a small copy, namely, reduce the original ....
I found this code, but for some reason it does not plow:

 $filename11 = $uploadfile; list($width, $height) = getimagesize($filename11); $new_width = 1024; $new_height = 724; $image_p = imagecreatetruecolor($new_width, $new_height); $image = imagecreatefromjpeg($filename11); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($image_p, 50); //50% это качество 0-100% 

Can someone tell me why it does not work, or knows another solution?

  • Need to “reduce” photo size or file size? - dekameron
  • In ideals, you need to reduce the file, since the files occupy 2-5 meg, and the extension is 2000-5000 psx (width), I thought to reduce the picture to 1024 (width), hence the file size will also decrease - arashvg
  • See imagejpeg description - alexlz
  • imagejpeg displays the image, and I just need to reduce its physical size on the server! - arashvg

2 answers 2

If you recall the description of the imagejpeg function, it becomes quite obvious that you forgot to specify the file name.

 imagejpeg($img,$filename,$quality); 

Let it be the same as the original. Then the original will be overwritten. If you don’t want to write so many things every time, create a simple class (interface example):

 interface ImageManager{ function resize($newWidth,$newHeight); function saveAs($filename); function save(); } 

    Here this article will help you a lot http://www.php.su/articles/?cat=graph&page=017 There's about everything, about compression, about scaling. In general, everything that will help reduce the weight of the image.