problem with transparency in composite command

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?".
ghost

problem with transparency in composite command

Post by ghost »

Hi,

I use a composite command with displacement map: composite map.png 1.png +matte -displace 0x30 2.png
1.png has transparent areas, but in 2.png all areas, that should be transparent, becomes black. How can I solve this problem?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: problem with transparency in composite command

Post by fmw42 »

I am not sure about transparency handling in -displace as that may not work or be very tricky due to the values in the transparency channel, but you can try adding -channel rgba before -matte NOT +matte. Note +matte turns off the alpha/transparency channel. If that does not work, hopefully Anthony can clarify. So write back and let us know if it works and so that he will see your reply.

Also be sure that map.png is single channel, so replace map.png with \( map.png -channel g \)

composite \(map.png -channel g \) \( 1.png -channel rgba -matte \) -displace 0x30 2.png


If this does not work, you may be able to handle it using the slower -fx. See viewtopic.php?f=1&t=12015
ghost

Re: problem with transparency in composite command

Post by ghost »

Thanks a lot, but in this way it also does not work properly. With composite command I have such problem as htvu in that topic - image id not distorted, only shifted by Y on 30px.

And when I use -fx, distortion strongly differs from what is carried out by 'composite':

1.png
Image

map.png
Image

composite map.png 1.png -displace 0x30 2.png
Image

composite map.png -channel g 1.png -channel rgba -matte -displace 0x30 2.png
Image

convert 1.png map.png -channel RGBA -fx \"p{i,v.g*h}\" 2.png
Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: problem with transparency in composite command

Post by fmw42 »

composite map.png -channel g 1.png -channel rgba -matte -displace 0x30 2.png
You may need to use the parentheses as I originally specified to ensure that each image uses the channel(s) required. If this does not work, then possibly -displace cannot handle transparency. But I will defer to Anthony on that.

composite \( map.png -channel g \) \( 1.png -channel rgba -matte \) -displace 0x30 2.png

see
http://www.imagemagick.org/Usage/basics/#parenthesis

If you are on Windows, then see also
http://www.imagemagick.org/Usage/api/#windows
as Windows uses different conventions and the parentheses don't need the \ escape
convert 1.png map.png -channel RGBA -fx \"p{i,v.g*h}\" 2.png
This was meant only as an example of one particular distortion and shows how to handle the transparency. You need to build your own -fx expression to do the distortion as you need it. But you see it does work with transparency.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: problem with transparency in composite command

Post by anthony »

ghost wrote:Thanks a lot, but in this way it also does not work properly. With composite command I have such problem as htvu in that topic - image id not distorted, only shifted by Y on 30px.

And when I use -fx, distortion strongly differs from what is carried out by 'composite':
The -fx version you are using is doing an absolute distortion. -displace is doing a relative distortion. The results is naturally quite different. You were just lucky they weren't far more different than that you actually achieved.

See http://www.imagemagick.org/Usage/distorts/#lut
for a general introduction to the two different methods.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
ghost

Re: problem with transparency in composite command

Post by ghost »

fmw42 wrote:You may need to use the parentheses as I originally specified to ensure that each image uses the channel(s) required. If this does not work, then possibly -displace cannot handle transparency. But I will defer to Anthony on that.
I use it, under Windows, but brackets doesn't do any effect in this expression.

Thank you for your help, but I have already found a Barrel distortion, that gives an effect very similar to my needs :)
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: problem with transparency in composite command

Post by fmw42 »

ghost wrote:[
Thank you for your help, but I have already found a Barrel distortion, that gives an effect very similar to my needs :)
IM as of 6.4.2-4 already has a barrel distortion. see http://www.imagemagick.org/Usage/distorts/#barrel

Also my texteffect script does the same, using an barrel inverse polynomial (but not yet converted to the new IM barrelinverse). see http://www.fmwconcepts.com/imagemagick/index.html
ghost

Re: problem with transparency in composite command

Post by ghost »

fmw42 wrote:IM as of 6.4.2-4 already has a barrel distortion. see http://www.imagemagick.org/Usage/distorts/#barrel
Yes, I also meant this, and use now :)
Also my texteffect script does the same, using an barrel inverse polynomial (but not yet converted to the new IM barrelinverse). see http://www.fmwconcepts.com/imagemagick/index.html
Thanks, I downloaded Texteffect but in my Windows under Cygwin it doesn't work :(
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: problem with transparency in composite command

Post by fmw42 »

Also my texteffect script does the same, using an barrel inverse polynomial (but not yet converted to the new IM barrelinverse). see http://www.fmwconcepts.com/imagemagick/index.html
Thanks, I downloaded Texteffect but in my Windows under Cygwin it doesn't work
Can you tell me where and or how it is failing? Does your Cygwin include the bc calculator?

What was your command line for using my texteffect?

It might be an IM version issue? But I would need to know what you were doing to check that.
ghost

Re: problem with transparency in composite command

Post by ghost »

Code: Select all

$ texteffect -t "SOME CONVEX TEXT" -s outline -e convex -d 0.35 -f Arial -p 48 -c skyblue -b white -o black -l 1 -u lightpink test.png
/usr/bin/texteffect: line 825: [: : integer expression expected
I use 6.4.3. bc installed.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: problem with transparency in composite command

Post by fmw42 »

Hello Ghost,
ghost wrote:

Code: Select all

$ texteffect -t "SOME CONVEX TEXT" -s outline -e convex -d 0.35 -f Arial -p 48 -c skyblue -b white -o black -l 1 -u lightpink test.png
/usr/bin/texteffect: line 825: [: : integer expression expected
I use 6.4.3. bc installed.

Thanks for the reply and notification. However, this line simply refers to a test of the IM version. But it requires the use of SED. Does your Cygwin include SED?

Try this:

im_version=`convert -list configure | \
sed '/^LIB_VERSION_NUMBER /!d; s//,/; s/,/,0/g; s/,0*\([0-9][0-9]\)/\1/g'`
echo "im_version=$im_version"

It should give something like:

im_version=06040308


Let me know what you get from this test. I suspect you do not have SED and so am getting an empty string for the result. Therefore the test of your version against the threshold version for using -distort vs -fx is giving an error.

Fred
ghost

Re: problem with transparency in composite command

Post by ghost »

Hm, it gives an empty string, but I have SED 4.1.5-2 in my Cygwin :/
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: problem with transparency in composite command

Post by fmw42 »

ghost wrote:Hm, it gives an empty string, but I have SED 4.1.5-2 in my Cygwin :/
Very strange. Can you try other SED commands? Perhaps part of this SED command is not valid for your version of Cygwin SED?

Try removing the \ and make it one long line?

im_version=`convert -list configure | sed '/^LIB_VERSION_NUMBER /!d; s//,/; s/,/,0/g; s/,0*\([0-9][0-9]\)/\1/g'`

Also try the following, which replaces SED with GREP, etc. I can change the script to substitute this, if it works for you.

im_version="0$(convert -list configure | grep 'LIB_VERSION_NUMBER' | cut -d\ -f2 | tr ',' '0')"
echo "$im_version"

or

im_version="0`convert -list configure | grep 'LIB_VERSION_NUMBER' | cut -d\ -f2 | tr ',' '0'`"
echo "$im_version"
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: problem with transparency in composite command

Post by anthony »

Just a word of caution. I do not recommend that 'grep' solution as it assumes that each of the version/patch numbers will be a single digit. That has not and probably will NOT always be the case, though it usually is.
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: problem with transparency in composite command

Post by fmw42 »

anthony wrote:Just a word of caution. I do not recommend that 'grep' solution as it assumes that each of the version/patch numbers will be a single digit. That has not and probably will NOT always be the case, though it usually is.

Good point. I had not thought of that, but have seen some minor version numbers above 9.
Post Reply