提示Trying to clone an uncloneable object of class Imagic的解決
更新時間:2011年10月27日 22:49:55 作者:
使用網上流傳的一個程序實現(xiàn)pdf截圖為png,需要使用Imagic擴展,安裝后出現(xiàn)Trying to clone an uncloneable object of class Imagic提示,下面是具體的解決方法分享。
使用網上流傳的一個程序實現(xiàn)pdf截圖為png,需要使用Imagic擴展。在windows下安裝完后提示:
Fatal error: Trying to clone an uncloneable object of class Imagick in C:\www\hx\pdf_to_png.php on line 17
使用IIS和Apache均會有這個提示。經多次測試后,發(fā)現(xiàn)兩種解決方法:
1.php.ini中; Enable compatibility mode with Zend Engine 1 (PHP 4.x)
zend.ze1_compatibility_mode = Off
默認是On,改為Off后,即可解決。
2.使用imagick::...這種方法調用。
即$im->setResolution(120, 120);可以改寫為:
imagick::setResolution(120, 120);
如果其它擴展出現(xiàn)這類錯誤,一般也是可以使用這兩種方法解決的。
附pdf轉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
使用IIS和Apache均會有這個提示。經多次測試后,發(fā)現(xiàn)兩種解決方法:
1.php.ini中; Enable compatibility mode with Zend Engine 1 (PHP 4.x)
zend.ze1_compatibility_mode = Off
默認是On,改為Off后,即可解決。
2.使用imagick::...這種方法調用。
即$im->setResolution(120, 120);可以改寫為:
imagick::setResolution(120, 120);
如果其它擴展出現(xiàn)這類錯誤,一般也是可以使用這兩種方法解決的。
附pdf轉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;
}
相關文章
phpStudy中升級MySQL版本到5.7.17的方法步驟
這篇文章主要給大家介紹了關于phpStudy中升級MySQL版本到5.7.17的方法步驟,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起看看吧。2017-08-08