PHP using Imagick to read PDFs and generate PNG thumbnail instances, imagickpng_php tutorial

Source: Internet
Author: User

PHP uses Imagick to read PDFs and generate PNG thumbnail instances, imagickpng


PDF Generate PNG home thumbnail (server needs to support Imagick)

Copy CodeThe code is as follows:
/**
* Pdf2png
* @param $pdf pending PDF file
* @param $path The path of the picture to be saved
* @param $page the page to be exported-1 for all 0 for the first page 1 for the second page
* @return saved picture path and file name.
*/
function Pdf2png ($pdf, $path, $page =0)
{
if (!is_dir ($path))
{
mkdir ($path, true);
}
if (!extension_loaded (' Imagick '))
{
Echo ' Didn't find imagick! ' ;
return false;
}
if (!file_exists ($pdf))
{
Echo ' did not find pdf ';
return false;
}
$im = new Imagick ();
$im->setresolution (120,120); Set the image resolution
$im->setcompressionquality (80); Compression ratio

$im->readimage ($pdf. " [". $page."] "); Set the first page of the read pdf
$im->thumbnailimage (max., true); Change the size of the image
$im->scaleimage (200,100,true); Scaled small 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 true http://www.bkjia.com/PHPjc/945707.html techarticle PHP uses Imagick to read PDFs and generate PNG thumbnail instances, imagickpng PDF generated PNG home thumbnail (server needs to support Imagick) copy code code as follows:/** * pdf2png * @para ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.