Page 1 of 1

Text on Partial Transparency

Posted: 2014-07-18T16:28:19-07:00
by Neon
I'm trying to generate (fully opaque) text from a file and place it on a generated semi-transparent image. Such as this:
Image

I'm trying to do this on the Command Line in Linux.

Code: Select all

$ convert -version
Version: ImageMagick 6.7.5-6 2012-08-11 Q16 ...
...
Features: OpenMP 
So the closest I have come, is this:

Code: Select all

convert -size 640x640 -alpha set xc:"rgba(0,127,255,0.5)" background.png
Image
Note: Partially transparent image. just what I want.

Code: Select all

convert -size 640x -background "rgb(0,127,255)" -gravity Center -font Nimbus-Sans-Regular -pointsize 18 caption:@text_file.txt foreground.png
Image
Note: Everything is opaque. That's what I want for the text, but not for it's background.

In theory, the next step would be to overlay the two images (the second image on the first) and emit the final image. But since the second image isn't right, I haven't gotten that far.
Most of what I've tried on the second line has generated amusing errors. For example, attempting to put any sort of transparency in the second line results in a black-on-black image. Say, by saying "-background none" or "xc:none" with or without a previous "-alpha set" argument. In fact, anytime the second line adds a canvas (via "xc" at least), then the foreground picture is not emitted, and a "temp-0.png" and "temp-1.png" picture are instead emitted. Attempts to go with modifying the alpha channel in the background (e.g. "-background 'rgba(0,127,255,0.5)'") are ignored, even if "-alpha set" is before it.

To recap: I want to overlay text onto a partially-transparent image and emit as a png file. The background image (semi-transparent blue) works good. The text image (black text from file onto (preferably) straight transparent) does not work. I'm looking for a proper way to generate the text (as fully opaque) for overlay onto the background image. Bonus points if you show the command for the overlay itself. Does not need to be a single line, but that's always nice to have (fewer intermediate temporary files to clean up afterward).

Re: Text on Partial Transparency

Posted: 2014-07-18T16:34:10-07:00
by fmw42
try this, which works for me on IM 6.8.9.5 Q16 Mac OSX, with different font and caption

convert -size 640x -background "rgba(0,127,255,0)" -gravity Center -font Nimbus-Sans-Regular -pointsize 18 caption:@text_file.txt foreground.png


It that does not work, you may need to upgrade IM. Your version is over 100 versions old.

Re: Text on Partial Transparency

Posted: 2014-07-18T16:53:58-07:00
by Neon
Thanks for your time, Fred. But it didn't work for me.
Time to force an upgrade, since my distro version has reached EOL and isn't receiving updated packages.

Re: Text on Partial Transparency

Posted: 2014-07-18T17:00:35-07:00
by fmw42
Did you use rgb or rgba? You need the latter?

Sorry I had a type. Try this

convert -size 200x -background "rgba(0,127,255,0.5)" -gravity Center -font Helvetica -pointsize 18 caption:TESTING tmp.png

Re: Text on Partial Transparency

Posted: 2014-07-18T23:09:08-07:00
by Neon
Unfortunately, I had tried that with the other stuff (such as separately setting the alpha channel), both setting the alpha channel in "rgba" to 1, 0, and numbers in between. It appears it's a problem with my version of imagemagick.

Re: Text on Partial Transparency

Posted: 2014-07-20T16:57:34-07:00
by Neon
Success!
I upgraded imagemagick and was able to get the one-liner Fred posted, to work.

Code: Select all

convert -size 640x -background "rgba(0,127,255,0.75)" -gravity Center -font Nimbus-Sans-L -pointsize 18 caption:@text_file.txt final_image.png;

Code: Select all

$ convert -version
Version: ImageMagick 6.8.6-3 2014-04-08 Q16 ...
...
Features: DPC OpenMP Modules
Delegates: bzlib djvu fftw fontconfig freetype gslib jng jp2 jpeg lcms lzma openexr pango png ps rsvg tiff wmf x xml zlib
Thanks much, Fred!