0

I tried this function to compress image while uploading to server. But images are uploaded without reducing the size of image. // Compress image function compressImage($source, $destination, $quality) {

$info = getimagesize($source);

if ($info['mime'] == 'image/jpeg') $image = imagecreatefromjpeg($source);

elseif ($info['mime'] == 'image/gif') $image = imagecreatefromgif($source);

elseif ($info['mime'] == 'image/png') $image = imagecreatefrompng($source);

imagejpeg($image, $destination, $quality);

}

1 Answers1

0

PHP is invoked AFTER the upload to the server is complete. To there is no way to compress an image during upload in PHP. The function you show here just opens an already uploaded image and saves it in JPEG format with the quality you put in the parameters.

See this thread on GZIP compression for requests. Thread on StackOverflow

Markus Müller
  • 2,611
  • 1
  • 17
  • 25