Trying to clone an object of class Imagic solution

  • 2020-05-12 02:18:19
  • OfStack

Prompt after installation under windows:
Fatal error: Trying to clone an uncloneable object of class Imagick in C:\www\hx\pdf_to_png.php on line 17

Use IIS and Apache with this tip. After many tests, two solutions were found:

1. php. ini; Enable compatibility mode with Zend Engine 1 (PHP 4.x)
zend.ze1_compatibility_mode = Off

The default is On. After changing to Off, it can be solved.

2. Use imagick: :... This method call.
$im - namely > setResolution (120, 120); It can be rewritten as:
imagick::setResolution(120, 120);


If this type of error occurs with other extensions, 1 can also be resolved using these two methods.

Attached is a code snippet from pdf to png:


        function pdf2png($pdf, $filename, $page=0) {          
            if (!extension_loaded('imagick')) {
                exit('no imagick');
                return false;                
            } 
            if (!file_exists($pdf)) {
                return false;
            }  
            $im = new Imagick();
            $im->setResolution(120, 120);
            $im->setCompressionQuality(100);
            $im->readImage($pdf . "[" . $page . "]");
            $im->setImageFormat('png');
            $im->writeImage($filename);
            $im->readImage($filename);
            $im->resizeImage(120, 150, Imagick::FILTER_LANCZOS, 1);
            $im->writeImage($filename);
            return $filename;
        }


Related articles: