Page 1 of 1

Problem with converting PDF to JPEG, Corrupt Image

Posted: 2008-07-13T04:34:38-07:00
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

Re: Problem with converting PDF to JPEG, Corrupt Image

Posted: 2008-07-13T08:23:05-07:00
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.

Re: Problem with converting PDF to JPEG, Corrupt Image

Posted: 2008-07-13T10:41:37-07:00
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 :)

Re: Problem with converting PDF to JPEG, Corrupt Image

Posted: 2008-07-13T11:36:18-07:00
by Bonzo
We need a copy of the pdf file.

Re: Problem with converting PDF to JPEG, Corrupt Image

Posted: 2008-07-13T11:55:04-07:00
by cargi
you can find the pdf at this address: http://www.igotmunchies.co.uk/sample.pdf

thanks :)

Re: Problem with converting PDF to JPEG, Corrupt Image

Posted: 2008-07-13T12:24:05-07:00
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

Re: Problem with converting PDF to JPEG, Corrupt Image

Posted: 2008-07-13T12:56:43-07:00
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

Re: Problem with converting PDF to JPEG, Corrupt Image

Posted: 2008-07-13T13:14:49-07:00
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

Re: Problem with converting PDF to JPEG, Corrupt Image

Posted: 2008-08-04T14:13:33-07:00
by cargi
man how much would you charge to develop this for me because i can't see where i am going soo wrong :(