2

As an extension to this question: How do I convert a PDF document to a preview image in PHP?

<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat( "jpg" );
header( "Content-Type: image/jpeg" );
echo $im;
?>

How do I use the code from the above question to create files on the server of the PDF's. The above code only displays the image.

Community
  • 1
  • 1
Kieran Andrews
  • 5,845
  • 2
  • 33
  • 57

2 Answers2

0

I think you could use imagejpeg();. Read about it in the PHP manual.

<?php
$im = new imagick('file.pdf[0]');
$im->setImageFormat( "jpg" );
header( "Content-Type: image/jpeg" );
echo $im;
imagejpeg($im, 'thumbnail.jpg');
?>

Edit: If the above doesn't work, you could try $im->writeImage('thumbnail.jpg');. I'm not familiar with Imagick, but according to this, it might work. Worth a shot? :P

Andrew
  • 12,172
  • 16
  • 46
  • 61
0

The code I used is as follows. It may help others with similar problems:

<?php
$file ="/var/www/assets/files/product_brochures/product_catalouge.pdf[0]";
$im = new imagick($file);
$im->setResolution( 100, 100 );   
$im->setImageFormat( "jpg" );
$height=$im->getImageHeight();
$width=$im->getImageWidth();

$im->cropImage($width/2, $height, 0, 0);

if ($height < $width)
  $im->scaleImage(44,0);
 else
  $im->scaleImage(0,60); 

$im->writeImage('thumbnail.jpg');
?>
Kieran Andrews
  • 5,845
  • 2
  • 33
  • 57