Rinsad Ahmed
Rinsad Ahmed

Reputation: 1943

Fatal error: Uncaught Error: Call to undefined method Imagick::flattenImages()

I have been using Imagick and ImageMagick in one of my Image processing scripts. It is working perfectly on my development server has the following configurations.

PHP Version 7.0.33 Imagick 3.4.3 ImageMagick 6.7.9-10 2016-05-05 Q16 http://www.imagemagick.org

But on my client's server, I am getting the following error.

Fatal error: Uncaught Error: Call to undefined method Imagick::flattenImages()

My client has the following configuration

PHP Version 7.2.15 Imagick 3.4.3 ImageMagick 7.0.7-11 Q16 x86_64 2017-11-20 http://www.imagemagick.org

I just wonder how the Imagick::flattenImages() is missing from my client's server as both my server and client's server has the same Imagick version

Upvotes: 0

Views: 1525

Answers (1)

Talk Nerdy To Me
Talk Nerdy To Me

Reputation: 672

Try this:

$image = new Imagick();
$image->readImage( $path_to_file );
$flattenedImage = $img->mergeImageLayers( imagick::LAYERMETHOD_FLATTEN );

PHP docs for Imagick::mergeImageLayers() method

You can also pass one of these constants as a layer method:

  • imagick::LAYERMETHOD_UNDEFINED (ImageMagick 6.2.9+)
  • imagick::LAYERMETHOD_COALESCE (ImageMagick 6.2.9+)
  • imagick::LAYERMETHOD_COMPAREANY (ImageMagick 6.2.9+)
  • imagick::LAYERMETHOD_COMPARECLEAR (ImageMagick 6.2.9+)
  • imagick::LAYERMETHOD_COMPAREOVERLAY (ImageMagick 6.2.9+)
  • imagick::LAYERMETHOD_DISPOSE (ImageMagick 6.2.9+)
  • imagick::LAYERMETHOD_OPTIMIZE (ImageMagick 6.2.9+)
  • imagick::LAYERMETHOD_OPTIMIZEPLUS (ImageMagick 6.2.9+)
  • imagick::LAYERMETHOD_OPTIMIZEIMAGE (ImageMagick 6.3.0+)
  • imagick::LAYERMETHOD_OPTIMIZETRANS (ImageMagick 6.3.0+)
  • imagick::LAYERMETHOD_REMOVEDUPS (ImageMagick 6.3.0+)
  • imagick::LAYERMETHOD_REMOVEZERO (ImageMagick 6.3.0+)
  • imagick::LAYERMETHOD_COMPOSITE (ImageMagick 6.3.0+)
  • imagick::LAYERMETHOD_MERGE (ImageMagick 6.3.7+)
  • imagick::LAYERMETHOD_FLATTEN (ImageMagick 6.3.7+)
  • imagick::LAYERMETHOD_MOSAIC (ImageMagick 6.3.7+)

Upvotes: 2

Related Questions