ImageMagick设置固定饱和度亮度并保留色相为何出现黑图?
-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
100on an 8-bit image gives you ~39% saturation (100/255), not full 100% saturation. - Setting Lightness (B channel) to
50gives 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

