D
D
Diversia2021-04-09 10:47:11
1C-Bitrix
Diversia, 2021-04-09 10:47:11

How to compress image quality?

There is a method:

CFile::ResizeImageFile(
  $image['tmp_name'], 
  $tmpImage, 
  array('width' => $maxW, 'height' => $maxH), 
  $resizeType,
  false,
  $quality
);

Sometimes there are pictures that are large in file size, but the width and height are small.
For example, a 681KB picture (841x561):
https://yadi.sk/i/7l4pKGhsW6ZK_A
We want to reduce the quality without changing the size (the picture is already small, why reduce it?). We set the same dimensions to the array, and set jpgQuality to 50. But the image does not change, the file is added without modification.

Please tell me what to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2021-04-13
@anton99zel

Resize only works when the original width or height changes. If you set the dimensions, but the picture is already smaller than your dimensions, then Resize will not work. That is why quality and other parameters will not be applied.
jpgQuality 50 is already bad. You will get a poor quality picture. And on pictures with a lower resolution, this will be especially noticeable.
I would set the Quality depending on the resolution of the original file.
Some results are more interesting when working with images with a php library.
Example
To compress the quality in your way, get the original size, and substitute it into the parameters minus 1 pixel.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question