Using a program circulated online to implement pdf screenshots as png, you need to use Imagic extensions. After installing under Windows, prompts:
Fatal error: Trying to clone an uncloneable object of class Imagick in C:\www\hx\pdf_to_png.php on line 17
This will be a prompt when using IIS and Apache. After multiple tests, two solutions were found:
; Enable compatibility mode with Zend Engine 1 (PHP)
zend.ze1_compatibility_mode = Off
The default is On, and it can be solved after changing to Off.
2. Use imagick::... to call this method.
That is, $im->setResolution(120, 120); can be rewritten as:
imagick::setResolution(120, 120);
If other extensions experience such errors, these two methods can generally be used to solve them.
Attached with a program 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;
}
Fatal error: Trying to clone an uncloneable object of class Imagick in C:\www\hx\pdf_to_png.php on line 17
This will be a prompt when using IIS and Apache. After multiple tests, two solutions were found:
; Enable compatibility mode with Zend Engine 1 (PHP)
zend.ze1_compatibility_mode = Off
The default is On, and it can be solved after changing to Off.
2. Use imagick::... to call this method.
That is, $im->setResolution(120, 120); can be rewritten as:
imagick::setResolution(120, 120);
If other extensions experience such errors, these two methods can generally be used to solve them.
Attached with a program code snippet from pdf to png:
Copy the codeThe 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;
}