How to dim or reduce opacity on annotation

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
jfrm
Posts: 3
Joined: 2018-10-31T15:30:12-07:00
Authentication code: 1152

How to dim or reduce opacity on annotation

Post by jfrm »

Trying to create a straightforward watermark, I've worked through the excellent examples section https://imagemagick.org/Usage/annotating/ but unfortunately all the syntax is for V6 whereas I have 7.0.8-14 Q16 x64 on Win10 and the syntax seems to have got a helluva lot more complicated.

Ideally, I would reproduce the final example which under V6 is: Here we create a simple label on a semi-transparent background, and overlay it.
convert -background '#00000080' -fill white label:'Faerie Dragon' miff:- |\
composite -gravity south -geometry +0+3 \
- dragon.gif anno_composite.jpg


but I've got nowwhere trying to convert that to V7 syntax. I wonder if anyone is clever enough to rewrite this in V7 syntax?

I could live with the prior example, however which is: ...get ImageMagick to use an 'undercolor' on a text box:
convert dragon.gif -fill white -undercolor '#00000080' -gravity South \
-annotate +0+5 ' Faerie Dragon ' anno_undercolor.jpg


and I've got somewhere with this - the following works:
magick bt.jpg -resize 800 -gravity center -pointsize 50 -fill white -undercolor lightgray -stroke white -strokewidth 2 -draw "text 0,120 ' © gamesboard.org.uk '" btannotated.jpg

except for the fact that the boxed text is not semi-transparent. It needs to have an opacity of 50% or whatever so that the image underneath is not completely obscured. All efforts to achieve that have failed dismally. Probably because I just don't understand what part of the old example is doing the dimming. I can't see anything in the syntax relating to opacity and if it's something about the code of '#00000080' in the undercolor that's doing it, the syntax doesn't work for the magick command. Can anyone advise how to render the text box with some transparency?

many thanks for any pointers...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to dim or reduce opacity on annotation

Post by snibgo »

jfrm wrote:I wonder if anyone is clever enough to rewrite this in V7 syntax?
Insert the word "magick" before "convert" and "composite". That works for IM v7.

However, the documention is very old. These days, we would use a single "magick" command:

Code: Select all

magick dragon.gif -background #00000080 -fill white label:"Faerie Dragon" -gravity south -geometry +0+3   -composite b.jpg
snibgo's IM pages: im.snibgo.com
jfrm
Posts: 3
Joined: 2018-10-31T15:30:12-07:00
Authentication code: 1152

Re: How to dim or reduce opacity on annotation

Post by jfrm »

Thank you. This was useful and gave me enough of a kick to get it working. I needed to read about how to specify a colour to understand the transparency part which was baffling me. Here is the final result that works quite well.

magick bt.jpg -resize 1024 -background "graya(40%, 0.4)" -pointsize 50 -fill "graya(90%, 0.4)" label:" copyright text " -gravity center -geometry +0+160 -composite btannotated.jpg
Kaitlyn225
Posts: 1
Joined: 2018-11-13T02:54:14-07:00
Authentication code: 1152

Re: How to dim or reduce opacity on annotation

Post by Kaitlyn225 »

I am developing an image processing tool that allows users to read/manipulate different image formats and set/change the attributes of them. I am using magick++ api, so command line processing is not the way I need. Basically, I want to enable the user to change the transparency of a png file. I tried setting the background attribute by

Code: Select all

int alpha = getThreshold(); Color c(0,0,0,alpha); image.backgroundColor(c);
but it didnt change anything. I also set the opacity by mobdro

Code: Select all

int c = getThreshold(); image.opacity(c);
but it didnt help either..hope it is clear now, thanks for your interest.
Last edited by Kaitlyn225 on 2018-12-26T02:41:08-07:00, edited 2 times in total.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to dim or reduce opacity on annotation

Post by snibgo »

Kaitlyn225 wrote:I am using magick++ api, so command line processing is not the way I need.
IM operations at the command line correspond to functions in the C and C++ apis.

Setting the background won't change individual pixels that already have values. You want to change the alpha values in an image. I expect ...

Code: Select all

    void alpha(const unsigned int alpha_);
... does what you want.
snibgo's IM pages: im.snibgo.com
Post Reply