2

i want to convert the PDF to image.But when the out put image generate it's get blur from original.Here is code

$uploadfile = ".pdf[53]";
$img = new Imagick($uploadfile);
$img->setResolution(300,300);
$img->resampleImage(150,150,imagick::FILTER_UNDEFINED,1);
$img->resizeImage(512,700,Imagick::FILTER_LANCZOS,0);
$img->setImageFormat('jpeg');
$img->setImageUnits(imagick::RESOLUTION_PIXELSPERINCH);
$img->writeImage ( "p-53.jpeg" );

Can you please help me. Thank you.

Sameer Z.
  • 3,265
  • 9
  • 48
  • 72
  • Z : Could you please share your full code i'm in need of converting an pdf to image in Codeigniter as i'm new to Codeigniter I'm stuckoff – user1894647 Jan 19 '16 at 07:13

1 Answers1

7

Remove the resample and the resize calls and see what you get. It looks like you are shrinking it and then upsizing it.

edit: setResolution(300,300) is too late -- the image has already been rendered. Do it like this:

$im = new Imagick(); 
$im->setResolution( 300, 300 ); 
$im->readImage( $uploadfile );
Lou Franco
  • 87,846
  • 14
  • 132
  • 192
  • Thanks for replay,but it did't work for me.Do have any other idea?I can do best with command line,but it slow in speed so i have switch back to php api.Here is command "urs/bin/convert -density 300x300 uploadfile.pdf[2] -resample 150 -resize 512x700! page.jpeg 2>&1"; – Sameer Z. Nov 18 '10 at 05:36
  • added another suggestion. PDF needs to know the resolution before you read it, since the file can be rendered at any resolution. It needs to know what you want before turning it into an image. – Lou Franco Nov 18 '10 at 13:44
  • 1
    Can you provide an example how to do it properly as I'm also looking for this solution? – user398341 Apr 21 '11 at 08:45