Possible bug when converting PNG to JPG

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
seanspotatobusiness
Posts: 8
Joined: 2013-11-19T05:23:43-07:00
Authentication code: 6789

Possible bug when converting PNG to JPG

Post 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)
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Possible bug when converting PNG to JPG

Post 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"
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug when converting PNG to JPG

Post by snibgo »

I'd use mogrify, not convert.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Possible bug when converting PNG to JPG

Post 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.
seanspotatobusiness
Posts: 8
Joined: 2013-11-19T05:23:43-07:00
Authentication code: 6789

Re: Possible bug when converting PNG to JPG

Post 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.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Possible bug when converting PNG to JPG

Post 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.
snibgo's IM pages: im.snibgo.com
Post Reply