8

I have ImageMagick 6.7.8-9 and cwebp and dwebp (libwebp, libwebp-devel) installed and working as expected from the command line.

I have php7.2 installed from webtatic.

the problem I'm facing is that php imagick is not wrking with webp extension (other formats are working fine) here's what I get when I try Imagick: Fatal error: Uncaught ImagickException: Unable to set image format in .... : Imagick->setimageformat('webp')

please help me, I googled a lot, stackoverflow has nothing regarding this issue.. any clue, guidance, answer will be apreciated, thanks in advance

sami
  • 81
  • 1
  • 4
  • 1
    Run `php -i | grep ImageMagick`. Is `WEBP` listed under "supported formats"? If not, you may need to install `Imagick` from source. – emcconville Mar 13 '18 at 12:44
  • 1
    thanks for your answer, I did so, it is not listed. but the thing is it works just fine from the command line **convert image.jpg image.webp** sorry if I look a bit annoying, but why doesn't it work? besides can I uninstall imagemagick 6 and install imagemagick 7 without affecting php's imagick? (i read somewhere that I should do so) – sami Mar 13 '18 at 13:10

1 Answers1

9

Don't use Imagick->setimageformat('webp') use the following syntax instead:

$imagick = new \Imagick('/tmp/foo.jpg'); $imagick->writeImage('webp:/tmp/foo.webp');

That should do the trick for you ;-)

Bernhard Rusch
  • 454
  • 4
  • 7
  • i used this method and output file has webp format but it's contents is with jpeg file format – iman Feb 21 '22 at 08:16