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

ImageMagick设置固定饱和度亮度并保留色相为何出现黑图?

Why does -evaluate set produce a black image in ImageMagick?

Great question—let's break down exactly what's going wrong here:

1. You're using the wrong value format for -evaluate set

When working with the HSL colorspace in ImageMagick, -evaluate set expects values that match the channel's native range (either 0-255 for 8-bit images, or 0.0-1.0 for floating-point). When you pass 100 or 50 without a percentage sign, ImageMagick interprets these as absolute values, not the percentages you intended.

For example:

  • Setting Saturation (G channel) to 100 on an 8-bit image gives you ~39% saturation (100/255), not full 100% saturation.
  • Setting Lightness (B channel) to 50 gives you ~19% lightness, which is very dark—but the full black result likely comes from the second mistake below.

To set percentages correctly, add a % sign to your values. ImageMagick will automatically scale these to the channel's valid range:

-evaluate set 100%  # Sets to full saturation (100%)
-evaluate set 75%   # Sets to 75% lightness

2. You forgot to convert back to RGB colorspace

After modifying channels in HSL, you need to convert the image back to the RGB colorspace before saving. If you skip this step, the image data remains in HSL format, but viewers will interpret it as RGB—leading to completely incorrect colors (often washed out, inverted, or in your case, solid black).

The corrected command

Here's the fixed version of your command that sets saturation to 100% and lightness to 75% correctly:

convert input.png -colorspace HSL \
  -channel G -evaluate set 100% \
  -channel B -evaluate set 75% \
  -colorspace RGB \
  output.png

Why your -evaluate multiply command worked

The multiply operation is relative—it scales existing channel values by a factor, so you don't have to worry about absolute ranges or percentage notation the same way. For example, 1.20 multiplies the saturation by 120%, which works seamlessly regardless of the image's bit depth.

内容的提问来源于stack exchange,提问作者simone

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.20 10:16:59