-1

I have installed Imagick dll successfully.I have followed following stackoverflow exmple

How do I convert a PDF document to a preview image in PHP?

following is my code

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

but i am now getting following error

Fatal error: Uncaught exception 'ImagickException' with message 'UnableToOpenBlob `demo.pdf': No such file or directory @ error/blob.c/OpenBlob/2657' in D:\xampp\htdocs\learn\index.php:2 Stack trace: #0 D:\xampp\htdocs\learn\index.php(2): Imagick->__construct('demo.pdf[0]') #1 {main} thrown in D:\xampp\htdocs\learn\index.php on line 2

Imagick dll installed propelry

Attached screnshot enter image description here Kindly some one help me how to fix this ?Thanks

Community
  • 1
  • 1
scott
  • 3,112
  • 19
  • 52
  • 90

1 Answers1

0
public function pdfToJpg($param){
        $filename = $param['filename'];
        $image_name = $param['image_name'];
        $path = $param['path'];
        $db_path = $param['db_path'];
        $im = new Imagick();
        $im->setResolution(220,220);
        $im->readimage($filename."[0]");
        $im->setImageFormat('jpeg');
        $im->setImageBackgroundColor('#ffffff');
        $im->flattenImages();
        $image_name = $image_name.".jpg";//"save_as_name.jpg";
        $imageprops = $im->getImageGeometry();
        /*if ($imageprops['width'] <= 175 && $imageprops['height'] <= 300) {
         // don't upscale
         } else {
         $im->resizeImage(175,300, imagick::FILTER_LANCZOS, 0.9, true);
         }*/

        $im->writeImage($path.$image_name);
        if($im){
            $Img = array();
            $Img['status'] = 1;
            $Img['image'] = ($db_path.$image_name);
            return $Img;
        }
        $im->clear();
        $im->destroy();
    }

Try It