/**
* PDF2PNG
* @param $pdf PDF file to be processed
* @param $path The path of the image to be saved
* @param $page The page to be exported -1 is all, 0 is the first page, 1 is the second page
* @return The path and file name of the saved image
*/
function pdf2png($pdf,$path,$page=0)
{
if(!is_dir($path))
{
mkdir($path,true);
}
if(!extension_loaded('imagick'))
{
echo 'imagick not found! ' ;
Return false;
}
if(!file_exists($pdf))
{
echo 'pdf not found' ;
return false;
}
$im = new Imagick();
$im->setResolution(120,120); //Set image resolution
$im->setCompressionQuality(80); //Compression ratio
$im->readImage($pdf."[".$page."]"); //Set the first page to read pdf
//$im->thumbnailImage(200, 100, true); //Change the size of the image
$im->scaleImage(200,100,true); //Scale the image
$filename = $path."/". time().'.png';
if($im->writeImage($filename) == true)
{
$Return = $filename;
}
Return $Return;
}
$s=pdf2png('file/1371273225-ceshi_ppt.pdf','images');
echo "
";