Page 1 of 1

Ignore missing images

Posted: 2012-06-18T14:26:51-07:00
by OrangeDog

Code: Select all

convert a.png b.png c.png -loop 0 out.gif
Is it possible to construct a command line similar to the above such that it won't fail if, for example, c.png does not exist and thus can't be loaded?
Whether the final animation has only two frames, or the missing frame is replaced with, for example, solid black I do not mind.

Re: Ignore missing images

Posted: 2012-06-18T15:29:42-07:00
by fmw42
I think it still works even with the error. This works for me on IM 6.7.7.8 Q16 beta.


convert rose: rose1.png rose: tmp.gif
convert: unable to open image `rose1.png': No such file or directory @ error/blob.c/OpenBlob/2634.

I still get tmp.gif with two frames even though I had no rose1.png image.

identify tmp.gif
tmp.gif[0] GIF 70x46 70x46+0+0 8-bit PseudoClass 256c 7.46KB 0.000u 0:00.000
tmp.gif[1] GIF 70x46 70x46+0+0 8-bit PseudoClass 256c 7.46KB 0.000u 0:00.000


I believe that this will junk the error message. It seems to work for me (from notes from Anthony)

convert rose: rose1.png rose: tmp2.gif 2>/dev/null

Anthony might have more details and better explanation than I.

Re: Ignore missing images

Posted: 2012-06-18T17:28:33-07:00
by anthony
You will not get an error, just a missing image file warning. As such it would still work.

You will get an write error is none of the image images were read, as no image file format allows zero images :-)

IM basically has four levels of error (exceptions)
no exception
warning (can be ignored, or made quiet)
error (commands will typically exit on this)
fatal (must exit - can not continue - typically a memory fault)

NOTE IMv6 CLI ("convert") saves up exceptions and reported them only when it exits. This is why some warnings can be slow to be recieved.
IMv7 CLI ("magick") reports non-exit exceptions immediately (then forgets them as they have been reported), and all others as it exits (already done).

Re: Ignore missing images

Posted: 2012-06-18T17:51:43-07:00
by fmw42
warning (can be ignored, or made quiet)
I had tried that but it still put out the warning.


convert -quiet rose: rose1.png rose: tmp.gif

convert: unable to open image `rose1.png': No such file or directory @ error/blob.c/OpenBlob/2634.
convert: unable to open file `rose1.png' @ error/png.c/ReadPNGImage/3698.

Re: Ignore missing images

Posted: 2012-06-18T22:14:28-07:00
by anthony
Hmmm. strange. I was sure it was a warning and not a error.
Note that it matters. It isn't a 'fatal' exception.

Re: Ignore missing images

Posted: 2012-06-19T02:06:28-07:00
by OrangeDog
However, a non-zero exit code is still given (1), making scripting very difficult.
This is good in most cases (as what was intended wouldn't have worked), but some way to ignore this specific problem would be grand.

Version is 6.7.6-1 Q8

Re: Ignore missing images

Posted: 2012-06-19T10:15:57-07:00
by fmw42
OrangeDog wrote:However, a non-zero exit code is still given (1), making scripting very difficult.
This is good in most cases (as what was intended wouldn't have worked), but some way to ignore this specific problem would be grand.

Version is 6.7.6-1 Q8

As I mentioned above, this seems to work to trash the error message so you don't see it. Don't know if that helps your situation.


convert rose: rose1.png rose: tmp2.gif 2>/dev/null

Re: Ignore missing images

Posted: 2012-06-19T12:00:02-07:00
by OrangeDog
No, being able to redirect the stderr stream to arbitrary places does not help with a non-zero exit code.

Re: Ignore missing images

Posted: 2012-06-19T16:10:08-07:00
by anthony
Looks like we will not be able to help you. IMv7 "magick" will have more control over the various exceptions do and what would be the final exit code, but it will still be some time before it is ready.