Home > Article > Backend Development > PHP uses Imagick to generate png thumbnails from pdf_PHP tutorial
If the thumbnail is a picture, we can directly use the php gD library. This article will introduce the method of Imagick to generate PNG thumbnails from PDF. Here we will use a plug-in. Let me show you an example. .
php_imagickwhat
A PHP extension that allows PHP to call the ImageMagick function. Using this extension allows PHP to have the same functionality as ImageMagick.
ImageMagick is a powerful, stable and free toolset and development package 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.
How to use php_imagick
. Create a thumbnail and display it
The code is as follows | Copy code | ||||||||||||||||||||
Okay, let’s get to the point.
* @param $pdf PDF file to be processed 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); //Zoom image
$filename = $path."/". time().'.png';
if($im->writeImage($filename) == true)
{
$Return = $filename;
}
Return $Return;
}
$s=pdf2png('file/1371273225-ceshi_ppt.pdf','images');
echo "";
http://www.bkjia.com/PHPjc/632954.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632954.htmlTechArticleIf the thumbnail is a picture, we can directly use the php gD library. This article will introduce Imagick How to generate png thumbnails from pdf. Here we have to use a plug-in. Next I will...
Statement: The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn Previous article:Program to generate transparent background png thumbnails in php_PHP tutorialNext article:Program to generate transparent background png thumbnails in php_PHP tutorial Related articlesSee more |