Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

How to use function Imagick?

Hi pro, I want to use Image Optimize. I read tutorial at https://cloudinary.com/blog/image_optimization_in_php I using Imagick but error with function: optimizeImageLayers(), setImageCompression(), setImageCompressionQuality() in Phalcon imagick error: Fatal error: Call to undefined method Phalcon\Image\Adapter\Imagick::optimizeImageLayers() in

$im = new \Phalcon\Image\Adapter\Imagick(APP_PATH . '/public/userfiles/goc.png');
        // Optimize the image layers
        $im->optimizeImageLayers(); 

        // Compression and quality
        $im->setImageCompression(Imagick::COMPRESSION_JPEG);
        $im->setImageCompressionQuality(25);

        // Write the image back
        $im->writeImages(APP_PATH . '/public/userfiles/new.png', true);

        $this->view->disable();

Hi @thanhansoft you have to use $im->getInternalImInstance() to get Imagick instance and make what you want

Good luck

Thank for reply. still bug Error: Fatal error: Call to undefined method Phalcon\Image\Adapter\Imagick::optimizeImageLayers() Please help me

$im = new \Phalcon\Image\Adapter\Imagick(APP_PATH . '/public/userfiles/goc.png');
        $im->getInternalImInstance(); 
        // Optimize the image layers
        $im->optimizeImageLayers(); 
        $this->view->disable();


12.8k
Accepted
answer
$im = new \Phalcon\Image\Adapter\Imagick(APP_PATH . '/public/userfiles/goc.png');
$im->getInternalImInstance()->optimizeImageLayers();    

Thank pro, I'm work success. This is full code

public function indexAction() {
        $im = new \Phalcon\Image\Adapter\Imagick(APP_PATH . '/public/userfiles/1.jpg');
        // Optimize the image layers
        $im->getInternalImInstance()->optimizeImageLayers();

        // Compression and quality
        $im->getInternalImInstance()->setImageCompression(\Imagick::COMPRESSION_JPEG);
        $im->getInternalImInstance()->setImageCompressionQuality(80);

        // Write the image back
        $im->getInternalImInstance()->writeImages(APP_PATH . '/public/userfiles/new.jpg', true);

        $this->view->disable();
    }