Page 1 of 1

detecting failure with convert

Posted: 2011-07-21T14:49:27-07:00
by abruzzi
I have an odd problem. I'm trying to use 'convert' to deal with about 100k TIFF images. All the TIFFs are single page, but we are converting them to multi-page TIFFs, so I'm using the following command:

Code: Select all

convert -monochrome -compress Group4 page1.tiff page2.tiff page3.tiff result.tiff
And it works perfectly. The problem arises from the fact that I know that in my 100k documents, there are bad files. So in the above example, if page2.tiff is corrupt, and convert can't read it, it still generates result.tiff as a two page document using page1.tiff and page3.tiff.

The ideal solution for me is that if any of the supplied pages are unreadable, the command fails with no generated files.

I do know that I can watch STDERR, but since my files generate all sorts of warnings, most of which don't constitute a failure to process the images, it's hard to know what actually do constitute an error.

I suspect my real solution is to stop trying to use 'convert', and use php/perl/python and the associated imagemagick library, but I was hoping to keep this simple.

Any thoughts?

Geof

Re: detecting failure with convert

Posted: 2011-07-21T15:17:46-07:00
by fmw42
see -quiet and -regard warnings at http://www.imagemagick.org/Usage/basics/#controls

try either

convert -quiet -regard-warnings image <options> resultimage

or

convert -quiet -regard-warnings image <options> resultimage ||
echo "--- FILE DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---"

Re: detecting failure with convert

Posted: 2011-07-21T15:59:37-07:00
by abruzzi
cool, playing around with your samples, the following does exactly what I need:

Code: Select all

convert -quiet -regard-warnings -monochrome -compress Group4 page1.tiff page2.tiff page3.tiff result.tiff || rm result.tiff
I need to run a larger scale test to make sure I'm not imagining things, but so far, if it hits a bad image in the bundle, it removes the result file.

thanks,

Geof