Ignore missing images

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
OrangeDog
Posts: 17
Joined: 2012-06-18T13:19:52-07:00
Authentication code: 13

Ignore missing images

Post 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.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Ignore missing images

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Ignore missing images

Post 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).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Ignore missing images

Post 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.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Ignore missing images

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
OrangeDog
Posts: 17
Joined: 2012-06-18T13:19:52-07:00
Authentication code: 13

Re: Ignore missing images

Post 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
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Ignore missing images

Post 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
OrangeDog
Posts: 17
Joined: 2012-06-18T13:19:52-07:00
Authentication code: 13

Re: Ignore missing images

Post by OrangeDog »

No, being able to redirect the stderr stream to arbitrary places does not help with a non-zero exit code.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Ignore missing images

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply