TryingtocloneanuncloneableobjectofclassImagic _ PHP-php Tutorial

Source: Internet
Author: User
If you use a program circulating on the Internet to implement the pdf file as png, you need to use the Imagic extension to install it in windows and then prompt:
Fatal error: Trying to clone an uncloneable object of class Imagick in C: \ www \ hx \ pai_to_png.php on line 17

This prompt is displayed when IIS and Apache are used. After multiple tests, we found two solutions:

1. in php. ini; Enable compatibility mode with Zend Engine 1 (PHP 4.x)
Zend. zemo-compatibility_mode = Off

The default value is On. after the value is changed to Off, the problem can be solved.

2. use imagick:... to call this method.
That is, $ im-> setResolution (120,120); can be rewritten:
Imagick: setResolution (120,120 );


If this type of error occurs for other extensions, you can use these two methods.

The code snippet for converting pdf to png:
The code is as follows:
Function ready 2png ($ 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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.