1、ImageMagick 安装 官网
> tar -zxvf ImageMagick.tar.gz -C /usr/local/src/
> cd /usr/local/src/ImageMagick-7.0.3-0/
> mkdir /usr/local/imagemagick
> ./configure --prefix=/usr/local/imagemagick
> make && make install
> /usr/local/imagemagick/bin/convert -version // 测试
2、安装 PHP 扩展 imagick 官网
> find / -name 'php-config' //查找 php-config 位置:
> find / -name 'phpize' //查找 phpize 位置:
> tar -zxvf imagick-3.4.1.tgz -C /usr/local/src/
> cd /usr/local/src/imagick-3.4.1/
> /usr/local/php/bin/phpize
> ./configure --with-php-config=/usr/local/php/bin/php-config --with-imagick=/usr/local/imagemagick
> make && make install
安装完成之后,出现下面的界面,记住以下路径,下面会用到
Installing shared extensions: /usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/
增加 imagick 扩展
> vim /usr/local/php/lib/php.ini
extension=/usr/local/php/lib/php/extensions/no-debug-non-zts-20131226/imagick.so
重启 PHP
> service php-fpm restart
3、安装 ghostscript (PDF转图片必备)
> yum -y install ghostscript
4、测试PHP
function pdf2png($PDF, $Path){
if(!extension_loaded('imagick')){
return false;
}
if(!file_exists($PDF)){
return false;
}
$IM = new imagick();
$IM->setResolution(120, 120);
$IM->setCompressionQuality(100);
$IM->readImage($PDF);
foreach($IM as $Key => $Var){
$Var->setImageFormat('png');
$Filename = $Path.'/'.md5($Key.time()).'.png';
if($Var->writeImage($Filename)==true){
$Return[]= $Filename;
}
}
return $Return;
}
$pdf = __DIR__.'/PDF/test.pdf';
$path = __DIR__.'/images';
$data = pdf2png($pdf, $path );
echo "SUCCESS";
参考来源:
http://superuser.com/questions/819277/cant-convert-pdf-into-image-because-of-no-images-defined-error