mask problem

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
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

mask problem

Post by Bonzo »

I am trying to create a grunge type font without success.

I have some text on a transparent background:

Code: Select all

convert -pointsize 200 -background none -fill blue label:"Anthony" text.png
I have a texture and I want to add the texture to the text and end up with the text on a transparent background and the texture to add transparent holes in the text.

The texture I am using: Image

I am converting the texture to a monochrome and inverting it before using it.

The problems I am having with different codes are:
If the texture is not the same size as the text image I get a size error.
The white areas I want transparent are staying white.
The text is black instead of blue.

Amongst other things I have tried:
convert input -mask -mask output
convert input mask -alpha off -compose copy-opacity -composite output

Please can somebody point me in the right direction.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask problem

Post by fmw42 »

I am not following your request. Do you want the blue text to have the grunge modulation or do you want the transparency to be replace by this grunge texture? In either case, you may need to crop out a section of your texture of the size of your text file to merge them.

IM will use the size of the first image for the size of the output, which is why you may need to crop before doing any composite.

Nevertheless, you can do some using the Duff-Porter compose methods.

So Is this what you want?

Code: Select all

convert text.png grunge.gif -gravity center -compose atop -composite result.png
or perhaps this?

Code: Select all

convert text.png grunge.gif -compose dstatop -composite result.png
Do you have an example of what you want done or can you explain a bit further?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: mask problem

Post by Bonzo »

I would like the effect of the text being a transfer and the transfer has been scratched and the background colour will show through both around the text and through the scratched areas.

This is one of my failures:
Image
The text is now black and it should be blue and the "scratches" are white and they should be transparent. The background is transparent so I have one out of three things correct!
Last edited by Bonzo on 2015-10-26T14:27:02-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask problem

Post by fmw42 »

See my modified message above. I still do not know exactly what you want.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask problem

Post by fmw42 »

try this

Code: Select all

convert text.png grunge.gif -gravity center -compose atop -composite text.png -compose over -compose multiply -composite result.png
or

Code: Select all

convert text.png \
\( -clone 0 grunge.gif -gravity center -compose atop -composite \) \
+swap -compose over -compose multiply -composite result.png
or

Code: Select all

convert text.png \
\( -clone 0 grunge.gif -gravity center -compose atop -composite \) \
+swap -compose over -compose blend -composite show:
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: mask problem

Post by Bonzo »

Thanks for the info and the last is the closest but the "scratched" areas are still white.

So I now have the blue text and the transparent background but as I say the scratches are white and need to be transparent.

Image

The bottom left still has a sort of "stroke/border" to the A which should not be there
Last edited by Bonzo on 2015-10-26T14:38:48-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask problem

Post by fmw42 »

try this:

Code: Select all

size=`convert text.png -format "%wx%h" info:`
convert text.png \
\( -clone 0 -alpha off \) \
\( -clone 0 -alpha extract \) \
\( grunge.gif -gravity center -crop $size+0+0 +repage \) \
\( -clone 2 -clone 3 -compose multiply -composite \) \
-delete 0,2,3 -compose over -compose copy_opacity -composite result.png
But you will need to convert my code to windows syntax.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask problem

Post by fmw42 »

This works without having to get the size first.

Code: Select all

convert text.png \
\( -clone 0 -alpha off \) \
\( -clone 0 -alpha extract \) \
\( -clone 2 grunge.gif -compose multiply -composite \) \
-delete 0,2 -compose over -compose copy_opacity -composite result.png
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask problem

Post by fmw42 »

Here it is putting both commands together.

Code: Select all

convert -pointsize 200 -background none -fill blue label:"Anthony" \
\( -clone 0 -alpha off \) \
\( -clone 0 -alpha extract \) \
\( -clone 2 grunge.gif -compose multiply -composite \) \
-delete 0,2 -compose over -compose copy_opacity -composite result.png
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: mask problem

Post by Bonzo »

Thank you very much fmw42 it works.

I would never have worked that out; I had assumed it would be something a lot simpler.

Image
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask problem

Post by fmw42 »

Basically you need to merge the alpha channel with the grunge image to be the new alpha channel. Using the crop method has the advantage that you can use any part of the grunge image.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mask problem

Post by fmw42 »

fmw42 wrote:Using the crop method has the advantage that you can use any part of the grunge image.
Actually you can use the latter method and get different parts of the grunge by adding -roll.

Code: Select all

convert -pointsize 200 -background none -fill blue label:"Anthony" \
\( -clone 0 -alpha off \) \
\( -clone 0 -alpha extract \) \
\( -clone 2 \( grunge.gif -roll -50-50 \) -compose multiply -composite \) \
-delete 0,2 -compose over -compose copy_opacity -composite result.png
Post Reply