first, what is ImageMagick?
ImageMagick is a powerful, stable, and free toolset and development kit that can be used to read, write, and process picture files in more than 185 basic formats, including popular TIFF, JPEG, GIF, PNG, PDF, and PHOTOCD formats. With ImageMagick, you can dynamically generate pictures based on the needs of your Web application, and you can resize, rotate, sharpen, subtractive, or add special effects to one (or a group) of pictures and save the results of the operation in the same format or in other formats.
Second, Php_imagick what
A php extension that allows PHP to invoke ImageMagick functionality. Using this extension enables PHP to have the same functionality as ImageMagick.
three, pdf to generate PNG thumbnail two ways
First type:
Copy Code code as follows:
/**
* Pdf2png
* @param $pdf PDF files to be processed
* @param $path picture path to save
* @param $page the page to be exported-1 is all 0 is the first page 1 is the second page
* @return saved picture path and filename
*/
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 Image resolution
$im->setcompressionquality (80); Compression ratio
$im->readimage ($pdf.) [". $page."]); Set the first page to read a PDF
$im->thumbnailimage (+, true); Change the size of an image
$im->scaleimage (200,100,true); Shrink Zoom Small Image
$filename = $path. " /". Time (). '. PNG ';
if ($im->writeimage ($filename) = = True)
{
$Return = $filename;
}
return $Return;
}
$s = pdf2png (' file/1371273225-ceshi_ppt.pdf ', ' images ');
Echo ' <div align= ' center ' ></div> ';
The second type:
Copy Code code 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;
}