Page 1 of 1

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

Posted: 2015-04-28T23:50:05-07:00
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.

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

Posted: 2015-04-28T23:59:31-07:00
by dlemstra
Can you convert ../books/58/58.pdf from the command line? It looks like that file is invalid.

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

Posted: 2015-04-29T00:22:49-07:00
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