Home > Backend Development > PHP Tutorial > Use Imagick in PHP to read pdf and generate png thumbnail examples, imagickpng_PHP tutorial

Use Imagick in PHP to read pdf and generate png thumbnail examples, imagickpng_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 10:09:28
Original
972 people have browsed it

Use Imagick in PHP to read pdf and generate png thumbnail example, imagickpng

Generate png homepage thumbnail from pdf (the server needs to support Imagick)

Copy code The code is as follows:

/**
* 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 "
";




http://www.bkjia.com/PHPjc/945707.html

www.bkjia.com

http: //www.bkjia.com/PHPjc/945707.htmlTechArticleImagick is used in PHP to read pdf and generate png thumbnail examples, imagickpng pdf generates png homepage thumbnails (server required Support Imagick) Copy the code code as follows: /** * PDF2PNG * @para...
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template