Page 1 of 1

colorize semi-transparent png

Posted: 2016-08-02T07:10:17-07:00
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?

Re: colorize semi-transparent png

Posted: 2016-08-02T09:02:12-07:00
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.

Re: colorize semi-transparent png

Posted: 2016-08-02T09:04:45-07:00
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

Re: colorize semi-transparent png

Posted: 2016-08-02T15:54:23-07:00
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?

Re: colorize semi-transparent png

Posted: 2016-08-02T16:04:31-07:00
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!

Re: colorize semi-transparent png

Posted: 2016-08-02T16:25:33-07:00
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.

Re: colorize semi-transparent png

Posted: 2016-08-02T17:07:17-07:00
by fmw42
I cannot get to your image from your link. So I cannot see what went wrong.

Re: colorize semi-transparent png

Posted: 2016-08-02T17:31:42-07:00
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

Re: colorize semi-transparent png

Posted: 2016-08-02T18:57:01-07:00
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.

Re: colorize semi-transparent png

Posted: 2016-08-02T20:42:57-07:00
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?

Re: colorize semi-transparent png

Posted: 2016-08-02T21:49:45-07:00
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

Re: colorize semi-transparent png

Posted: 2016-08-02T23:16:48-07:00
by theatrain
OK thanks. I tried that script and it kind of worked but didn't keep the shadows.

Re: colorize semi-transparent png

Posted: 2016-08-02T23:44:51-07:00
by fmw42
Looks fine to me. But I suspect it is your IM 6.7.7.10 version.