Page 1 of 1

Possible bug when converting PNG to JPG

Posted: 2013-11-19T05:32:55-07:00
by seanspotatobusiness
Below are the commands and output from my attempt to convert some PNGs to JPG. I just had six images named 11-2013_1808_1, 11-2013_1808_2 etc. The first attempt fails with an error. In the second attempt, I specify the complete filename of the first file and the JPG is created as expected. In the third attempt, all PNGs are now converted but are named -2013_1808_1-0.png, -2013_1808_1-1.png etc. What causes this? It looks like some sort of hysteresis.

Code: Select all

C:\redacted>convert *.png *.jpg
convert.exe: unable to open image `*-0.jpg': Invalid argument @ error/blob.c/OpenBlob/2643.

C:\redacted>convert 11-2013_1808_1.png 11-2013_1808_1.jpg

C:\redacted>convert *.png *.jpg

C:\redacted>
Windows 7 (64-bit), ImageMagick 6.8.7 Q16 (64-bit)

Re: Possible bug when converting PNG to JPG

Posted: 2013-11-19T05:37:47-07:00
by Bonzo
I would guess the - in the filename is the problem and the first thing I would do is try renaming a file without the - and see what happens.

In your second example you could try enclosing the filename in "11-2013_1808_1.png"

Re: Possible bug when converting PNG to JPG

Posted: 2013-11-19T05:57:00-07:00
by snibgo
I'd use mogrify, not convert.

Re: Possible bug when converting PNG to JPG

Posted: 2013-11-19T11:49:59-07:00
by glennrp
seanspotatobusiness wrote:

Code: Select all

C:\redacted>convert *.png *.jpg
convert.exe: unable to open image `*-0.jpg': Invalid argument @ error/blob.c/OpenBlob/2643.

C:\redacted>convert 11-2013_1808_1.png 11-2013_1808_1.jpg

C:\redacted>convert *.png *.jpg

C:\redacted>
The target "*.jpg" is incorrect.
First attempt: *.jpg does not exist so it failed.
Second attempt: created 11-2013_1808_1.jpg
Third attempt: *.jpg is now 11-2013_1808_1.jpg so that is the
target and you get the output files you saw.

First attempt would have worked if you used a template name rather than *.jpg

Code: Select all

convert *.png 11-2013_1808_%d.jpg
Now you'll get 11-2013_1808_0.jpg, 11-2013_1808_1.jpg, etc.

Re: Possible bug when converting PNG to JPG

Posted: 2013-11-20T09:59:35-07:00
by seanspotatobusiness
glennrp wrote:
seanspotatobusiness wrote:

Code: Select all

C:\redacted>convert *.png *.jpg
convert.exe: unable to open image `*-0.jpg': Invalid argument @ error/blob.c/OpenBlob/2643.

C:\redacted>convert 11-2013_1808_1.png 11-2013_1808_1.jpg

C:\redacted>convert *.png *.jpg

C:\redacted>
The target "*.jpg" is incorrect.
First attempt: *.jpg does not exist so it failed.
Second attempt: created 11-2013_1808_1.jpg
Third attempt: *.jpg is now 11-2013_1808_1.jpg so that is the
target and you get the output files you saw.

First attempt would have worked if you used a template name rather than *.jpg

Code: Select all

convert *.png 11-2013_1808_%d.jpg
Now you'll get 11-2013_1808_0.jpg, 11-2013_1808_1.jpg, etc.
Thanks. I don't understand why ImageMagick needs a jpg file to already exist though. What I really wanted was each file to have the same name as the corresponding png, just in jpg format with a jpg extension.

Thanks again.

Re: Possible bug when converting PNG to JPG

Posted: 2013-11-20T10:19:37-07:00
by snibgo
I think mogrify will suit your purpose better.

Code: Select all

mogrify -format jpg *.png
This will create one jpg file for each existing png file, with the same name but different extension.