Trouble with transparency of imported text for overlay

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
scampa123
Posts: 4
Joined: 2017-02-08T11:55:51-07:00
Authentication code: 1151

Trouble with transparency of imported text for overlay

Post by scampa123 »

I'm hoping someone can help me with a transparency issue...

I am reading in text to create an image with a transparent background with the text in it:

Code: Select all

convert -size 1000x1000  -font Arial caption:@text.txt -background none  -fill black -channel alpha text.gif
text.txt is the multi-line text file
text.gif is the outputted file...

Next I attempt to overlay this onto an existing photo:

Code: Select all

composite -gravity center text.gif note2.jpg   compose_over.gif
The result is that the text image is overlayed onto the photo, but it maintains a white background. The background photo has white in it, however they do not match and it is obvious that the text.gif has been overlayed...

Am I doing something obvious wrong here?? Can Anyone help?

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

Re: Trouble with transparency of imported text for overlay

Post by fmw42 »

What is your IM version and platform? Please always provide that with questions, since syntax may vary.

Your first command is incorrect and is creating a white background and not transparent. Your second command is ok, but you would be better using the convert syntax, since it is more flexible. You can also combine the two commands into one.

Separate commands:

Code: Select all

convert -size 100x100 -background none -font Arial -fill black caption:@text.txt -trim +repage text.gif
convert note2.jpg text.gif -gravity center -compose over -composite result.gif
Combined commands (Unix syntax)

Code: Select all

convert note2.jpg \
\( -size 100x100 -background none -font Arial -fill black caption:@text.txt -trim +repage \) \
-gravity center -compose over -composite result.gif
Combined commands (Windows syntax)

Code: Select all

convert note2.jpg ^
( -size 100x100 -background none -font Arial -fill black caption:@text.txt -trim +repage ) ^
-gravity center -compose over -composite result.gif
Use a different -gravity setting and -geometry to place the text image somewhere else on your note2.jpg image.

See
http://www.imagemagick.org/script/comma ... hp#gravity
http://www.imagemagick.org/script/comma ... p#geometry
http://www.imagemagick.org/Usage/layers/#convert
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble with transparency of imported text for overlay

Post by fmw42 »

P.S. On current versions of IM, you cannot use @text.txt unless you modify your policy.xml file to permit that. IM has tightened security via the policy.xml file. You would need to change the line for the @ symbol. So you need to change

<!-- <policy domain="path" rights="none" pattern="@*"/> -->

To uncomment it and set the rights to "read | write"

But I assume you are using a very old version of IM or have done this already.
scampa123
Posts: 4
Joined: 2017-02-08T11:55:51-07:00
Authentication code: 1151

Re: Trouble with transparency of imported text for overlay

Post by scampa123 »

Wow! Thank you!! It works!!!

fmw42 wrote: 2017-02-08T12:42:00-07:00 What is your IM version and platform? Please always provide that with questions, since syntax may vary.

Your first command is incorrect and is creating a white background and not transparent. Your second command is ok, but you would be better using the convert syntax, since it is more flexible. You can also combine the two commands into one.

Separate commands:

Code: Select all

convert -size 100x100 -background none -font Arial -fill black caption:@text.txt -trim +repage text.gif
convert note2.jpg text.gif -gravity center -compose over -composite result.gif
Combined commands (Unix syntax)

Code: Select all

convert note2.jpg \
\( -size 100x100 -background none -font Arial -fill black caption:@text.txt -trim +repage \) \
-gravity center -compose over -composite result.gif
Combined commands (Windows syntax)

Code: Select all

convert note2.jpg ^
( -size 100x100 -background none -font Arial -fill black caption:@text.txt -trim +repage ) ^
-gravity center -compose over -composite result.gif
Use a different -gravity setting and -geometry to place the text image somewhere else on your note2.jpg image.

See
http://www.imagemagick.org/script/comma ... hp#gravity
http://www.imagemagick.org/script/comma ... p#geometry
http://www.imagemagick.org/Usage/layers/#convert
scampa123
Posts: 4
Joined: 2017-02-08T11:55:51-07:00
Authentication code: 1151

Re: Trouble with transparency of imported text for overlay

Post by scampa123 »

This just worked for me. I just set all this up, so I assume its the latest...


fmw42 wrote: 2017-02-08T12:48:26-07:00 P.S. On current versions of IM, you cannot use @text.txt unless you modify your policy.xml file to permit that. IM has tightened security via the policy.xml file. You would need to change the line for the @ symbol. So you need to change

<!-- <policy domain="path" rights="none" pattern="@*"/> -->

To uncomment it and set the rights to "read | write"

But I assume you are using a very old version of IM or have done this already.
scampa123
Posts: 4
Joined: 2017-02-08T11:55:51-07:00
Authentication code: 1151

Re: Trouble with transparency of imported text for overlay

Post by scampa123 »

btw I'm on a Mac with the Mac Ports and installed it that way...
scampa123 wrote: 2017-02-08T13:05:45-07:00 This just worked for me. I just set all this up, so I assume its the latest...


fmw42 wrote: 2017-02-08T12:48:26-07:00 P.S. On current versions of IM, you cannot use @text.txt unless you modify your policy.xml file to permit that. IM has tightened security via the policy.xml file. You would need to change the line for the @ symbol. So you need to change

<!-- <policy domain="path" rights="none" pattern="@*"/> -->

To uncomment it and set the rights to "read | write"

But I assume you are using a very old version of IM or have done this already.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Trouble with transparency of imported text for overlay

Post by fmw42 »

Well, then perhaps the policy comes that way and it is up to the user to restrict the policy as desired for security. Sorry, I do not recall which way it installs.
Post Reply