Detect transparency
Detect transparency
Ive got an image. I want to modify this image and create a mask so that all transparent areas get for instance red, and all areas without transparency(Anything from white to red) gets for instance blue.. How is it possible to do this?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Detect transparency
What you are asking is not clear enough as saying everything from white to red should go to blue is vague as to what that really means. However, if by that you mean make the red channel black (so it goes away) and put the old red channel into the blue, then try this:
convert logo2t.png \
\( -clone 0 -channel rgba -separate \) \
\( -clone 0 -channel r -fx "black" \) \
-delete 0 \
-swap 0,2 -swap 0,4 -delete 4 -channel rgba -combine \
-fill red -opaque none \
logo2t_finish.png
second line: separate all channel r,g,b,a
third line: create black image size of original
fourth line: delete original
fifth line: swap red with blue, swap black with new red (now black), delete old red, recombine all channels
sixth line: make any transparent areas red
original image (note transparent on light gray background will be light gray):
here is the result:
convert logo2t.png \
\( -clone 0 -channel rgba -separate \) \
\( -clone 0 -channel r -fx "black" \) \
-delete 0 \
-swap 0,2 -swap 0,4 -delete 4 -channel rgba -combine \
-fill red -opaque none \
logo2t_finish.png
second line: separate all channel r,g,b,a
third line: create black image size of original
fourth line: delete original
fifth line: swap red with blue, swap black with new red (now black), delete old red, recombine all channels
sixth line: make any transparent areas red
original image (note transparent on light gray background will be light gray):
here is the result:
Re: Detect transparency
What I want to do is create a mask. and the mask is gonna be like this:
Ive got an image. Let's say this:
I want all transparent areas to go "#FF00FF" and the rest to go transparent. It would produce this result:
Or as I asked in the first post, this can be an alternaive:
The basic idea of why I want this is because I got a watermark which I only want to place on non-transparent spots. So by creating this mask and overlaping it onto the watermark, I will prevent the watermark from going on transparent spots. If there is any easier ways, please tell me
I use #FF00FF as transparent areas on watermark and #FFFFFF as colored areas. So by overlaping a mask of the original image's transparency where transparent areas are replaced with #FF00FF and all other areas with transparency(any color can act as transparency druing merging). I will remove any white areas from the watermark where the transparency is.
Watermark + Mask
+ =
Ive got an image. Let's say this:
I want all transparent areas to go "#FF00FF" and the rest to go transparent. It would produce this result:
Or as I asked in the first post, this can be an alternaive:
The basic idea of why I want this is because I got a watermark which I only want to place on non-transparent spots. So by creating this mask and overlaping it onto the watermark, I will prevent the watermark from going on transparent spots. If there is any easier ways, please tell me
I use #FF00FF as transparent areas on watermark and #FFFFFF as colored areas. So by overlaping a mask of the original image's transparency where transparent areas are replaced with #FF00FF and all other areas with transparency(any color can act as transparency druing merging). I will remove any white areas from the watermark where the transparency is.
Watermark + Mask
+ =
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: Detect transparency
This produces the first version with the transparent background
and this one makes a blue background
Pete
Code: Select all
convert logo2t.png -channel a -separate +channel -fill #FF00FF -opaque white -transparent black logo2t_trans.png
Code: Select all
convert logo2t.png -channel a -separate +channel -fill #FF00FF -opaque white -fill blue -opaque black logo2t_blue.png
Re: Detect transparency
On second thoughts:
It works perfectly on my computer! (ImageMagick 6.4.2 Q16)
But on my webpage it doesnt do anything! (ImageMagick 6.3.6)
Does the version of imagemagick got to do something with this or is it someting lse which is wrong? The code doesnt output any error messages either..
It works perfectly on my computer! (ImageMagick 6.4.2 Q16)
But on my webpage it doesnt do anything! (ImageMagick 6.3.6)
Does the version of imagemagick got to do something with this or is it someting lse which is wrong? The code doesnt output any error messages either..
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Detect transparency
Thanks Pete!
It would have been nice if he had made it clear exactly what he wanted to do and not made some vague question.
Fred
It would have been nice if he had made it clear exactly what he wanted to do and not made some vague question.
Fred
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: Detect transparency
As far as I know, the command should work with IM6.3.6. I don't know why it won't work on your webpage.Liquix wrote:But on my webpage it doesnt do anything! (ImageMagick 6.3.6)
Pete
Re: Detect transparency
I found out..
Had to use this code instead:
Seems the " is required on some enviroments
Had to use this code instead:
Code: Select all
convert logo2t.png -channel a -separate +channel -fill "#FF00FF" -opaque white -transparent black logo2t_trans.png
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Detect transparency
An alternative for solid colors is...Liquix wrote:Ive got an image. I want to modify this image and create a mask so that all transparent areas get for instance red, and all areas without transparency(Anything from white to red) gets for instance blue.. How is it possible to do this?
Code: Select all
convert image.png -fill blue -colorize 100% \
-background red -flatten colored_mask.png
http://www.imagemagick.org/Usage/channels/#extract
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
https://imagemagick.org/Usage/