1. What is ImageMagick
ImageMagick is a set of powerful, stable and free tools and development kits that can be used to read, write and process image files in more than 185 basic formats, including popular TIFF, JPEG, GIF, PNG, PDF and PhotoCD formats. Using ImageMagick, you can dynamically generate images according to the needs of web applications. You can also change the size, rotate, sharpen, reduce color or add special effects to an image (or a group of images), and save the results in the same format. or save in other formats.
2. What is php_imagick?
A PHP extension that allows PHP to call the ImageMagick function. Using this extension allows PHP to have the same functionality as ImageMagick.
3. Two ways to generate png thumbnails from PDF
The first one:
Copy the code The code is as follows:
/**
* PDF2PNG
* @param $pdf PDF file to be processed
* @param $path Image path to be saved
* @param $page Page to be exported - 1 for all 0 for 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 '
div>';
Second type:
Copy code The code is as follows: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;
}
http://www.bkjia.com/PHPjc/743932.html
www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/743932.htmlTechArticle1. What is ImageMagick? ImageMagick is a set of powerful, stable and free toolsets and development kits that can be used To read, write and process image files in over 185 basic formats, including...