You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使GraphicsMagick生成的ALPHA水印具备75%透明度?

How to create a 75% transparent "ALPHA" watermark in GraphicsMagick?

Question

I'm trying to add a large, semi-transparent "ALPHA" watermark to an image using GraphicsMagick. Here's the code I've put together so far:

gm convert \ 
-background transparent \ 
-fill '#5968c3' \ 
-font Arial \ 
-size 140x80 \ 
-pointsize 190 \ 
-gravity center \ 
-draw "text 0,0 ALPHA" \ 
-matte \ 
-pointsize 16 \ 
-gravity southeast \ 
-draw "text 10,10 \"©2018 Hunter Ltd\"" \ 
input.png \ 
output.png

Right now the watermark is solid, no transparency at all. How can I tweak this to make the "ALPHA" text 75% transparent?

Answer

Hey, nice start with your code! Getting that semi-transparent watermark is straightforward once you know that GraphicsMagick lets you include transparency directly in your color definition. Here's how to fix it:

The core fix: Add alpha to your fill color

Instead of using a plain hex color like #5968c3, you need to add an alpha component. There are two easy ways to do this:

  1. Hex RGBA format: Append two hex digits to your color code to set opacity. Since you want 75% transparency, that means the text should be 25% opaque. Hex values for alpha range from 00 (fully transparent) to FF (fully solid). 25% of 255 (the max value) is ~64, which translates to 40 in hex. So your fill color becomes #5968c340.

  2. RGBA function syntax: Use rgba(r,g,b,alpha) where alpha is a decimal between 0 (transparent) and 1 (solid). For 75% transparency, alpha is 0.25 (since 1 - 0.75 = 0.25 opacity). Your fill color here would be rgba(89,104,195,0.25) (those numbers are the RGB values of #5968c3 converted to decimal).

Updated code example

Here's your full code with the hex RGBA fix applied to the "ALPHA" watermark:

gm convert \ 
-background transparent \ 
-fill '#5968c340' \  # Added 40 for 25% opacity (75% transparency)
-font Arial \ 
-size 140x80 \ 
-pointsize 190 \ 
-gravity center \ 
-draw "text 0,0 ALPHA" \ 
-matte \ 
-pointsize 16 \ 
-gravity southeast \ 
-draw "text 10,10 \"©2018 Hunter Ltd\"" \ 
input.png \ 
output.png

If you prefer the RGBA syntax, just swap the -fill line with:

-fill 'rgba(89,104,195,0.25)' \

Quick tip

If you ever want to adjust the transparency level later, just remember:

  • Solid (100% opacity) = FF (hex) or 1.0 (RGBA)
  • 50% transparent = 80 (hex) or 0.5 (RGBA)
  • Fully transparent = 00 (hex) or 0.0 (RGBA)

And if you want the copyright text to be transparent too, just apply the same alpha trick to its -fill value (though it looks like you probably want that one solid, so you can leave it as is).

内容的提问来源于stack exchange,提问作者Sardathrion - against SE abuse

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.25 08:27:48