Problem with converting PDF to JPEG, Corrupt Image

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
cargi

Problem with converting PDF to JPEG, Corrupt Image

Post by cargi »

Hi guys,

I am having a problem when uploading PDF files. I have sucessfully managed to upload one at about 20kb in size but when I try uploading a document at 500kb it isnt working and saysing 'corrupt image'. Any ideas or advice would be greatly appreciated.

Thanks,

Cargi
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problem with converting PDF to JPEG, Corrupt Image

Post by Bonzo »

The first thing you are going to be asked is "can you provide an example file" and the second thing is what "version are you using" and finaly "can you post an example of your code".

Nobody can help you without the information above.
cargi

Re: Problem with converting PDF to JPEG, Corrupt Image

Post by cargi »

Hi there,

You can find an example at http://www.iGotMunchies.co.uk/register.php

The code I am using is as follows:

$filename = '';

$targetdir = 'uploads/menus/';


include('imagemagick_class.php');

$imObj = new ImageMagick($_FILES['image1']);

$imObj -> setVerbose(TRUE);

$imObj -> setTargetdir($targetdir);

$imObj -> Convert(jpg);
$filename = $imObj -> Save();
$imObj -> CleanUp();



$imObj2 = new ImageMagick($_FILES['image2']);

$imObj2 -> setVerbose(TRUE);

$imObj2 -> setTargetdir($targetdir);

$imObj2 -> Convert(jpg);
$filename2 = $imObj2 -> Save();
$imObj2 -> CleanUp();

Thanks :)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problem with converting PDF to JPEG, Corrupt Image

Post by Bonzo »

We need a copy of the pdf file.
cargi

Re: Problem with converting PDF to JPEG, Corrupt Image

Post by cargi »

you can find the pdf at this address: http://www.igotmunchies.co.uk/sample.pdf

thanks :)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problem with converting PDF to JPEG, Corrupt Image

Post by Bonzo »

Works Ok for me using:

Code: Select all

<?php
exec("convert sample.pdf sample.jpg");
?>
I do not know what size you want but this will give a better quality image:

Code: Select all

<?php
exec("convert -density 300 sample.pdf -resize 50% sample.jpg");
?>
IM version 6.4.0 04/16/08 Q16
cargi

Re: Problem with converting PDF to JPEG, Corrupt Image

Post by cargi »

Hi Bronzo,

Thanks for the help, one i should of said earlier is that I am using the imagemagick_class file. This looks to be what would normally be
exec("convert sample.pdf sample.jpg");

I quess it is a problem within the imagemagick_class file then.

$command = "{$this->imagemagickdir}/convert -colorspace RGB -quality {$this->jpg_quality} '{$this->temp_dir}/tmp{$this->count}_{$this->temp_file}' '{$this->temp_dir}/tmp".++$this->count."_{$name}'";

The class file can be found at http://www.bokko.nl/projects/php-imagemagick-class
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problem with converting PDF to JPEG, Corrupt Image

Post by Bonzo »

I did notice you were using a class and I have quickly tried it but I get "Imagemagick: Upload failed"; I am not that interested in finding how it works at the moment and so will not look at it any further.

If the code I posted works then it must be the class if not there must be a problem with the IM or Ghostscript install.

The class looks a bit OTT if all you want to do is upload and resize an image, this is an example of a form to do the same thing I wrote a few years ago: http://www.rubblewebs.co.uk/imagemagick/codes/thumb.php
cargi

Re: Problem with converting PDF to JPEG, Corrupt Image

Post by cargi »

man how much would you charge to develop this for me because i can't see where i am going soo wrong :(
Post Reply