I saw how get parameters compress images on the site. for example http://site.com/img.jpg?w=100&h=150&c=7 how to implement it. The bottom line is that I want to upload pictures to the site in good resolution, and then compress the client, make the quality a little worse, change the size, how to implement it?
|
2 answers
May be useful
public function optimize($image) { $size = 512; $ext = pathinfo($image); if (!array_key_exists('extension',$ext)){ throw new Exception('Отсутствует разширение файла!'); } if (!array_key_exists('filename',$ext)){ throw new Exception('Отсутствует имя файла!'); } $extension = $ext['extension']; if($extension == ""){ throw new Exception('Отсутствует разширение файла!'); } $im = new Imagick($image); $height = $im->getImageHeight(); $width = $im->getImageWidth(); if($height < $size && $width < $size){ $im->adaptiveResizeImage($width,$height); } if($height > $size && $width > $size && $height == $width){ $im->adaptiveResizeImage($size,$size); } if($height > $width && $height > $size){ $im->adaptiveResizeImage(0,$size); } if($width > $height && $width > $size){ $im->adaptiveResizeImage($size,0); } // Optimize the image layers $im->optimizeImageLayers(); // Compression and quality $im->setImageCompression(Imagick::COMPRESSION_JPEG); $im->setImageCompressionQuality(55); // Write the image back $im->writeImages($image, true); } - Any answer that guides the questioner in the right direction is valuable. A short answer is also possible, but the more detailed and clearer it is, the better. To improve this answer, you can add information about the library that is used in the solution, what it is for, connection methods, a link to the documentation. - Uranus
|
I think that the simplest option is to install imagemagick and reap with the help of its convert or mogrify utilities via system ()
It wants to integrate more tightly - there is a down module .
|
Yii2 glide.. yes, he cuts them, everything is cool, but the processing on the server is too long ... there was page 1.4, it loads for 180-300DOM, after glide it became 1.2 and it loads 360DOM + - user292806