Script failing on certain 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
SharkD
Posts: 35
Joined: 2006-07-30T13:18:31-07:00

Script failing on certain images

Post by SharkD »

I'm using the following script to convert a directory full of images such that the blue background color is replaced with transparency.

Code: Select all

convert "images_mecha_big_dithered\aer_bee1.png" -alpha set -channel RGBA -depth 8 -fill none -opaque blue "images_mecha_big_dithered\alpha\aer_bee1.png"
It works for most files, but it fails on certain ones, producing the unwanted side-effect of turning the result of the operation into an 8-bit paletted PNG file instead of 32-bit.

I can't identify any differences in the input images. They're all 48-bit (don't ask me why...) PNG images with the subject material composed on top of the same blue background.

Here are two examples: the first one fails, the second one works.

Image Image

Hopefully ImageShack didn't mess around with the images after I uploaded them.

This problem really has me stumped. Would appreciate any input.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Script failing on certain images

Post by fmw42 »

they both work fine for me under IM 6.6.7.4 Q16 Mac OSX tiger.

Please note that the PNG format has been under quite a bit of development over the last number of releases for improvements and bug fixes. However, there were some releases where things were not properly worked out and new bugs were introduced. So you might want to upgrade your IM as you did not identify what version you were using or platform (always a good idea)

see the changelog for information at http://www.imagemagick.org/script/changelog.php


In the mean-time, you could try prefacing your output image with PNG32:yourimagename.png and see if that helps.
SharkD
Posts: 35
Joined: 2006-07-30T13:18:31-07:00

Re: Script failing on certain images

Post by SharkD »

Sorry about that. Here's the file name of the installer I used:

Code: Select all

ImageMagick-6.6.7-4-Q16-windows-x64-static.exe
fmw42 wrote:In the mean-time, you could try prefacing your output image with PNG32:yourimagename.png and see if that helps.
Just tried this, but the images don't get written to the output directory. Instead, a 0-byte file named "PNG32" (no extension) gets written to the output directory.

[edit]

Just tried again, this time instead using BMP images as the input. Same results.

[edit]

I also can't seem to locate any Windows binaries for any previous releases.
SharkD
Posts: 35
Joined: 2006-07-30T13:18:31-07:00

Re: Script failing on certain images

Post by SharkD »

OK, I determined by carefully examining the images that ImageMagick is dropping to 8-bit paletted images whenever the source image has fewer than 256 unique colors (regardless of the bit depth).

I'd much rather it always outputted a 32-bit image, but don't know how to get it to do that.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Script failing on certain images

Post by fmw42 »

try adding -type truecolormatte and PNG32:output.png
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Script failing on certain images

Post by anthony »

Just the later PNG32:filename.png should be enough!
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: Script failing on certain images

Post by fmw42 »

anthony wrote:Just the later PNG32:filename.png should be enough!
That is what I suggested first, but he said it did not work. Seems like a Windows/IM issue.
SharkD
Posts: 35
Joined: 2006-07-30T13:18:31-07:00

Re: Script failing on certain images

Post by SharkD »

I've decided to throw in the towel. Right now I am mainly just displaying the images in a Web browser, so it doesn't really matter whether the file is 32 bits or 8 bits with a transparency index as long as it looks the same. I was hoping for a single, consistent output format - the images may be imported into a video game at some point in the future, at which point it potentially could end up posing a *REAL* issue - but I'll deal with that situation if/when it arises. Hopefully by then the bug or issue will be fixed within ImageMagick (assuming that it really is an IM issue...).

Regardless, thank you everyone for your help!!
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Script failing on certain images

Post by fmw42 »

seeing as how I had no problem with processing either of your images on my Mac, perhaps you should report this as a bug for IM windows. someone should be able to confirm on Windows if they have the same issue.
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: Script failing on certain images

Post by glennrp »

PNG32: should work. Does it help to put quotes around it, on Windows?
Maybe the colon is getting swallowed up somehow and PNG32: is being
interpreted as a drive letter or something. Just guessing.

Code: Select all

convert inputfile "PNG32:output.png"
You could also use -define PNG:color-type=6 to force RGBA PNG output.
Post Reply