Using 'display' to show a png with transparent background.

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
uncertain

Using 'display' to show a png with transparent background.

Post by uncertain »

Hi,
I'm not too experienced with IM, and am having trouble getting the display command to do what I want. I've searched the forum here, but haven't found anything that directly applies to what I'm looking for.

I have a .png file - an icon. It has a transparent background, and I want it to display with the transparency intact, as opposed to a solid-black or checkerboard background. I'm structuring my command as such:

Code: Select all

display -alpha on -resize WWxHH -geometry +XXX+YYY FILENAME.png
I've tried using other operators under the -alpha switch. Neither Transparent nor Opaque are recognized as valid, which may be due to the somewhat outdated version of IM that's available in the Ubuntu 8.04 repositories. (I'm compiling the latest source as I write this.) How can I get the transparent areas of a file - be it .png or whatever - to actually be transparent when displayed via the display command?

For a second problem, the image displayed in that manner will have a light-gray border around it. I can change the color to any color name available as described under the -fill command (except for 'none' or 'transparent' both of these options cause errors; unrecognized option/file not found, or some such thing). I've tried surrounding the name in quotes, I've tried using the rgba values '(00 00 00 0.0)' - everything I try there also causes errors.

While the command

Code: Select all

display -bordercolor "transparent" -alpha on -resize WWxHH -geometry +XXX+YYY FILENAME.png
causes errors, even when "transparent" is changed to "none", the command

Code: Select all

display -bordercolor "peachpuff" -alpha on -resize WWxHH -geometry +XXX+YYY FILENAME.png
will work correctly, and any color name shown on the -fill command page will work as well.

Why can't I get transparency to work at all? I assume it's something I'm doing wrong in my command structure, but can't quite figure it out. After spending a couple of days pouring through man pages and command definitions, everything starts to look the same and I'm finding myself working in circles, trying the same things again and again.

For the record, I'm using Ubuntu 8.04, current on all updates, and my terminal tells me this about my installed version of IM

Code: Select all

~$ display --version
Version: ImageMagick 6.3.7 02/19/08 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2008 ImageMagick Studio LLC
Thanks in advance for any help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using 'display' to show a png with transparent background.

Post by fmw42 »

You are on a very old version of IM. Try upgrading.

However, display should not need or may not be sensitive to other IM commands. If your png has transparency, it should display as transparent with just

display transparentimage.png

try this

convert logo: -fuzz 10% -transparent white logo.png
display logo.png

On my Mac OSX with IM 6.5.0-9 Q16, when I do that I get the logo image displayed with a checkerboard background where the image (formerly white) is transparent.
uncertain

Re: Using 'display' to show a png with transparent background.

Post by uncertain »

That's the newest version in the Hardy repos. I don't think they've backported it yet.

I got an error when I tried compiling the source. ./confgure and make went alright, but I got shot down when doing sudo make install. there were some unmet dependencies and I couldn't find them in standard repos.

It's weird you say transparency should work straightaway.. Even in th GUI that pops up when you click a displayed image, if I select color=none under the border color options, I get an error that says "'none' is a color unknown to X server." It's strange, because I can view/create/modify/whatever images with transparency in pretty much any other application - gimp, kolourpaint, qiv, etc..
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Using 'display' to show a png with transparent background.

Post by fmw42 »

uncertain wrote:That's the newest version in the Hardy repos. I don't think they've backported it yet.

I got an error when I tried compiling the source. ./confgure and make went alright, but I got shot down when doing sudo make install. there were some unmet dependencies and I couldn't find them in standard repos.

It's weird you say transparency should work straightaway.. Even in th GUI that pops up when you click a displayed image, if I select color=none under the border color options, I get an error that says "'none' is a color unknown to X server." It's strange, because I can view/create/modify/whatever images with transparency in pretty much any other application - gimp, kolourpaint, qiv, etc..

If you are on a Mac and having trouble manually installing IM, then see some notes I wrote when I first got IM installed on my Mac OSX Tiger. Don't know about differences with Leopard.

viewtopic.php?f=1&t=13145

Hope this helps
Post Reply