Using PHPs inbuilt image compression function imagejpeg I did a test to find out is it worth compressing images? and is there a big difference?
The usage is simple for imagejpeg you need to pass a jpeg in, specify its output and then a value for its quality (0 – 100).
imagejpeg does however require that the input is created from a PHP image create function. Its silly but here is a function to make it all simple:
function comp($in, $out, $qual) { $img = imagecreatefromjpeg($in); // load the image-to-be-saved imagejpeg($img, $out, $qual); }
to compress an image
comp('full.jpg', '90.jpeg', 90);
The file size decreased a lot the lower the quality value got. 45 was 3 times smaller, whilst 75 saw the file size cut in half. Even 85 saw over 150 KB in file size saving. Its pretty evident that imagejpeg cuts file size.
The quality of the images surprised me, there was very minor change, given my starting jpg file was just a phone image the file quality degraded as you pixel peeped anyway.
The original image on the far left, quality at 70 in the middle and quality 45 on the far right. You cant notice any difference.
Again given that the starting original image was already somewhat compressed (VSCO) maybe imagejpeg could really squish them down. But it doesn’t really matter if the image was compressed to begin with because it got an even better compression.
Imagejpeg is worth using, even if you use a quality level like 80
![imagejpeg compression php imagejpeg compression php](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/i_view32_2018-10-27_09-58-19-700x434.jpg)
I will attach all the compressed images below for you to see.
![45 45](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/45-700x872.jpeg)
![50 50](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/50-700x872.jpeg)
![55 55](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/55-700x872.jpeg)
![60 60](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/60-700x872.jpeg)
![65 65](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/65-700x872.jpeg)
![70 70](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/70-700x872.jpeg)
![75 75](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/75-700x872.jpeg)
![80 80](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/80-700x872.jpeg)
![85 85](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/85-700x872.jpeg)
![90 90](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/90-700x872.jpeg)
![full full](https://cpwp.b-cdn.net/wp-content/uploads/2018/10/full-700x872.jpg)