Jump to content

PNG to WebP conversion (output format)


Recommended Posts

Hey, devs. I have a question about converting image attachments.

So, if we use Imagick, PNG images are not compressed at all. 8 out of 10 images that I uploaded to the post have a larger file size than before uploading (lol).

I wrote some code to compress PNG images (by changing the format to webp) and the size dropped by about 80% (sic!), however I need code to save the output file in .webp format. 

Can anyone direct me how to change the output format after uploading?

/* Get Format */
$format = $this->imagick->getImageFormat();
	      
/* Set PNG */
if( mb_strtolower( $format ) == 'png' )
{
$this->imagick->setImageFormat('webp');
$this->imagick->setOption('webp:filter-strength', '20');
$this->imagick->setOption('webp:filter-type', '0');
$this->imagick->setOption('webp:method', '3');
$this->imagick->setImageCompressionQuality( 85 );
}
Edited by SeNioR-
Link to comment
Share on other sites

  • 9 months later...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...