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, it prompts:
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, changing it to Off will solve the problem.
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, it is generally OK. Solved using these two methods.
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;
}
http://www.bkjia.com/PHPjc/324507.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/324507.htmlTechArticleUse a program circulated on the Internet to convert pdf screenshots into png, and you need to use the Imagic extension. After installation under windows, it prompts: Fatal error: Trying to clone an uncloneable object of class Im...
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