colorize semi-transparent png

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
theatrain
Posts: 6
Joined: 2016-08-02T06:59:42-07:00
Authentication code: 1151

colorize semi-transparent png

Post by theatrain »

I have a transparent png which has a window frame in the middle. I want to overlay a flat colour e.g. 'red' with a multiply blend, how can i achieve this?

Source image - http://i.stack.imgur.com/JBetn.png
Desired result (red overlay) - http://i.stack.imgur.com/UsHFX.png

This is easy to achieve in Photoshop by applying a layer effect > color overlay > blend mode: multiply, but I can't seem to work out how to apply this programmatically. Can somebody please help?
User avatar
GeeMack
Posts: 718
Joined: 2015-12-01T22:09:46-07:00
Authentication code: 1151
Location: Central Illinois, USA

Re: colorize semi-transparent png

Post by GeeMack »

theatrain wrote:Source image - http://i.stack.imgur.com/JBetn.png
Desired result (red overlay) - http://i.stack.imgur.com/UsHFX.png

This is easy to achieve in Photoshop by applying a layer effect > color overlay > blend mode: multiply, but I can't seem to work out how to apply this programmatically. Can somebody please help?
Using IM7 from a Windows command prompt I can easily duplicate your result with this command...

Code: Select all

magick JBetn.png ( +clone -fill red -colorize 100% ) -compose multiply -composite result.png
To get proper help you should always provide the version of IM you're using, the operating system you're working on, and the command(s) you've already tried.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: colorize semi-transparent png

Post by fmw42 »

Please always provide your IM version and platform, since syntax differs:

Unix:

Code: Select all

convert JBetn.png \( -clone 0 -fill red -colorize 100% \) -compose multiply -composite result.png
Window:

Code: Select all

convert JBetn.png ( -clone 0 -fill red -colorize 100% ) -compose multiply -composite result.png
theatrain
Posts: 6
Joined: 2016-08-02T06:59:42-07:00
Authentication code: 1151

Re: colorize semi-transparent png

Post by theatrain »

Version: ImageMagick 6.7.7-10 2016-06-01 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2012 ImageMagick Studio LLC
Features: OpenMP

When I run that command in my current version I get the attached - http://imgur.com/a/d0Mga

Is there anyway to get the result I am after with my current version?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: colorize semi-transparent png

Post by fmw42 »

I cannot get to your image. Furthermore, you IM version is ancient and does not look like it has any delegates or have you cut off the listing? Your version is about 175 versions old. So I do not know if it has a bug in this regard. You still do not say what platform you are using!
theatrain
Posts: 6
Joined: 2016-08-02T06:59:42-07:00
Authentication code: 1151

Re: colorize semi-transparent png

Post by theatrain »

It is a web application running on an ubuntu server, details below:

Distributor ID: Ubuntu
Description: Ubuntu 14.04.4 LTS
Release: 14.04
Codename: trusty

Sorry for the lack of details, first post on this forum.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: colorize semi-transparent png

Post by fmw42 »

I cannot get to your image from your link. So I cannot see what went wrong.
theatrain
Posts: 6
Joined: 2016-08-02T06:59:42-07:00
Authentication code: 1151

Re: colorize semi-transparent png

Post by theatrain »

You can't see this -http://i.imgur.com/yKKDn9p.png?

Just confirming that I have upgraded my version of imagick on Ubuntu 14.04 as per instructions below from this link - http://sysads.co.uk/2016/05/how-to-inst ... rivatives/

wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar -xvf ImageMagick.tar.gz
cd ImageMagick-7.*
./configure
make
sudo make install
sudo ldconfig /usr/local/lib

I now run the command below and get the desired output

convert JBetn.png \( -clone 0 -fill red -colorize 100% \) -compose multiply -composite result.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: colorize semi-transparent png

Post by fmw42 »

I could not get to the web page before, but I can now. But it seems you have upgraded and the problem is gone.
theatrain
Posts: 6
Joined: 2016-08-02T06:59:42-07:00
Authentication code: 1151

Re: colorize semi-transparent png

Post by theatrain »

Yes the upgrade fixed it on the command line but I am building a php application and am struggling to get php-imagick to use IM v7 behind the scenes. The currently supported version of IM on ubuntu 14.04LTS is ImageMagick 6.7.7-10 2016-06-01 Q16 and it seems that this is a bug in this version. Is there any other way to get the result I am after with v6.7.7?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: colorize semi-transparent png

Post by fmw42 »

I do not think Imagick works with IM 7, since it is a major change and Imagick is not keeping up even with IM 6 changes. I would try upgrading to the latest IM 6.

Otherwise, try

Code: Select all

convert JBetn.png -channel rgba -negate -background red -flatten result.png
theatrain
Posts: 6
Joined: 2016-08-02T06:59:42-07:00
Authentication code: 1151

Re: colorize semi-transparent png

Post by theatrain »

OK thanks. I tried that script and it kind of worked but didn't keep the shadows.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: colorize semi-transparent png

Post by fmw42 »

Looks fine to me. But I suspect it is your IM 6.7.7.10 version.
Post Reply