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


i'm on following

ubuntu 12.04 lts php 5.3.10-1ubuntu3.18 suhosin-patch (cli) imagemagick 6.6.9-7 gpl ghostscript 9.05 (2012-02-08) 

my gs under /usr/bin

i'm converting continuously - pdf jpg each pdf page single image. worked first time 1-30 sets of pdf i'm getting error after 7 sets of pdf being complete

running php script in command line. after converting 5-7 sets of pdf jpg separate images (about 1000 jpg) i'm getting following error

php fatal error: uncaught exception 'imagickexception' 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 script convert pdf jpg - code 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 document // each page 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 images for($i = 0;$i < $num_pages; $i++) { // set iterator postion $img->setiteratorindex($i); // set image format $img->setimageformat('jpeg'); // write images temp 'upload' folder $img->writeimage("../books/$book_id/pages/$i".'.jpg'); } $img->destroy();  ?> 

after getting error stop converting, when run script again works 5-7 sets of pdf , stop again. can please tell me i'm missing here.

i appreciate kind help. thank in advance.

as @kens suggested, case calling ghostscript directly better, both faster, , not crash.

i suspect issue you're seeing resource being held open imagemagick, , @ point processing starts failing because there no more of resource available.

if wanted investigate that, strace tool with. calling gs directly allow on more important stuff.


Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -