Home >Backend Development >PHP Tutorial >cloneable prompt Trying to clone an uncloneable object of class Imagic solution

cloneable prompt Trying to clone an uncloneable object of class Imagic solution

WBOY
WBOYOriginal
2016-07-29 08:46:581064browse

Use a program circulated on the Internet to convert pdf screenshots into png, and you need to use the Imagic extension. After installation under Windows, the prompt is:
Fatal error: Trying to clone an uncloneable object of class Imagick in C:wwwhxpdf_to_png.php on line 17
This prompt will appear when using IIS and Apache. 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 it to Off, that is Can be solved.
2. Use imagick::... to call.
That is, $im->setResolution(120, 120); can be rewritten as:
imagick::setResolution(120, 120);
If this kind of error occurs in other extensions, these two methods can generally be used to solve it.
Attached is the program code snippet for converting pdf to png:

Copy the code The code is as follows:


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;
}

The above has introduced the solution to the cloneable prompt Trying to clone an uncloneable object of class Imagic, including the cloneable content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn