ImageMagick getting uncaught Fatal error after doing 5-7 sets of PDF to JPG

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
blackbird
Posts: 2
Joined: 2015-04-28T23:24:14-07:00
Authentication code: 6789

ImageMagick getting uncaught Fatal error after doing 5-7 sets of PDF to JPG

Post by blackbird »

I'm on as following
Ubuntu 12.04 LTS
PHP 5.3.10-1ubuntu3.18 with Suhosin-Patch (cli)
ImageMagick 6.6.9-7
GPL Ghostscript 9.05 (2012-02-08)

my gs is under /usr/bin

I'm converting continuously - PDF to JPG images separately. It worked first time for 1-30 sets of PDF but now I'm getting error after 7 sets of PDF being complete

running the PHP script in command line. After converting 5-7 sets of PDF to JPG separate images (about 1000 JPG) i'm getting the following error

PHP Fatal error: Uncaught exception 'ImagickException' with message 'Postscript delegate failed `../books/58/58.pdf': @ error/pdf.c/ReadPDFImage/663' in /var/www/mysite/public_html/admin/lib.php:10
Stack trace:
#0 /var/www/mysite/public_html/admin/lib.php(10): Imagick->__construct('../books/58/58....')
#1 /var/www/mysite/public_html/admin/test.php(118): include('/var/www/stagin...')
#2 {main}
thrown in /var/www/mysite/public_html/admin/lib.php on line 10

lib.php has the script to convert the PDF to JPG - code as below
<?php
$file_name = "../books/$book_id/$book_id".'.pdf';
mkdir("../books/$book_id/pages");

// Strip document extension
$file_name = basename($file_name, '.pdf');

// Convert this document
// Each page to single image
$img = new imagick("../books/$book_id/$book_id".'.pdf');

// Set image resolution
// Determine num of pages
$img->setResolution(300,300);
$num_pages = $img->getNumberImages();

// Convert PDF pages to images
for($i = 0;$i < $num_pages; $i++) {
// Set iterator postion
$img->setIteratorIndex($i);
// Set image format
$img->setImageFormat('jpeg');
// Write Images to temp 'upload' folder
$img->writeImage("../books/$book_id/pages/$i".'.jpg');
}
$img->destroy();

?>

After getting the error it stop the converting, but when I run the script again it works for another 5-7 sets of PDF and stop again.
Can anyone please tell me what i'm missing here.

I appreciate your kind help.
Thank you in advance.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: ImageMagick getting uncaught Fatal error after doing 5-7 sets of PDF to JPG

Post by dlemstra »

Can you convert ../books/58/58.pdf from the command line? It looks like that file is invalid.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
blackbird
Posts: 2
Joined: 2015-04-28T23:24:14-07:00
Authentication code: 6789

Re: ImageMagick getting uncaught Fatal error after doing 5-7 sets of PDF to JPG

Post by blackbird »

I just tried again the script, and ended up with the 61.pdf with the same error.
Now I checked with command line with that PDF 61.pdf, it works fine. Also the file is valid, you can see staging.knowyourbook.com/books/61/61.pdf
Can you help me further on the issue?.

Thanks
Sahed
Post Reply