You can test for quality loss by using PHP GD
and see if it suits you. you can also do this while uploading the image:
function compressImage($source_path, $destination_path, $quality) {
$info = getimagesize($source_path);
if ($info['mime'] == 'image/jpeg') {
$image = imagecreatefromjpeg($source_path);
} elseif ($info['mime'] == 'image/png') {
$image = imagecreatefrompng($source_path);
}
imagejpeg($image, $destination_path, $quality);
return $destination_path;
}
Explaining the functions used:
-
getimagesize()
: returns the image information (type, size, dimensions, etc.), we use to achieve the MIME Type of the original image.
-
imagecreatefromjpeg()
: creates a new image from the original image.
-
imagejpeg()
: send an image to the browser or to a file, this is where the lighter image is created.
Finally the function returns the path of the lighter image.
Usage example: $img = compressImage("images/praia.jpg", "images/compressed/compressed_praia.jpg", 6);