Page 1 of 1
Script failing on certain images
Posted: 2011-02-03T13:09:23-07:00
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.
Hopefully ImageShack didn't mess around with the images after I uploaded them.
This problem really has me stumped. Would appreciate any input.
Re: Script failing on certain images
Posted: 2011-02-03T13:46:07-07:00
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.
Re: Script failing on certain images
Posted: 2011-02-03T14:14:54-07:00
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.
Re: Script failing on certain images
Posted: 2011-02-03T15:27:13-07:00
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.
Re: Script failing on certain images
Posted: 2011-02-03T18:04:08-07:00
by fmw42
try adding -type truecolormatte and PNG32:output.png
Re: Script failing on certain images
Posted: 2011-02-03T18:36:18-07:00
by anthony
Just the later PNG32:filename.png should be enough!
Re: Script failing on certain images
Posted: 2011-02-03T18:41:28-07:00
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.
Re: Script failing on certain images
Posted: 2011-02-04T12:05:25-07:00
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!!
Re: Script failing on certain images
Posted: 2011-02-04T13:33:03-07:00
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.
Re: Script failing on certain images
Posted: 2011-02-04T14:00:11-07:00
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.