Default Watermark Color RRGGBBAA in ImageKit: Complete Technical Guide
The default watermark color in ImageKit is #FFFFFF80 (white with 50% opacity), defined in src/cli.rs as HexColor(Rgba([255, 255, 255, 128])).
The ImageKit Rust library provides a command-line interface for batch image processing, including watermarked overlays. Understanding the default watermark color RRGGBBAA configuration is essential for developers customizing output aesthetics or implementing automated image pipelines.
Default Watermark Color Definition in src/cli.rs
The default watermark color is hardcoded in the CLI configuration struct at lines 33-34 of src/cli.rs. The Cli struct defines the watermark_color field with the following default instantiation:
#[derive(Parser)]
struct Cli {
/// Watermark color in RRGGBBAA format
#[arg(long, default_value_t = HexColor(Rgba([255, 255, 255, 128])))]
watermark_color: HexColor,
}
This RGBA tuple contains four u8 values:
- Red: 255 (0xFF)
- Green: 255 (0xFF)
- Blue: 255 (0xFF)
- Alpha: 128 (0x80)
When converted to hexadecimal RRGGBBAA notation, these values produce #FFFFFF80, representing pure white at 50% opacity. The HexColor wrapper struct handles serialization and deserialization between the string representation and the internal Rgba<u8> pixel type.
Watermark Color Flow Through the Processing Pipeline
After parsing, the default watermark color propagates through the processing pipeline via the add_watermark function in src/processor.rs. This function receives the HexColor value and extracts the underlying Rgba<u8> for drawing operations:
use imagekit::cli::Cli;
use imagekit::processor::add_watermark;
use image::DynamicImage;
// Parse CLI args with default watermark_color (no --watermark-color flag provided)
let args = Cli::parse_from(&["imgkit", "-i", "input.jpg", "-o", "output.jpg"]);
// The default resolves to Rgba([255, 255, 255, 128]) -> #FFFFFF80
assert_eq!(args.watermark_color.0, Rgba([255, 255, 255, 128]));
// Apply watermark using the default white semi-transparent color
let mut img = image::open("input.png")?;
let fonts = imagekit::assets::load_default_fonts()?;
add_watermark(
&mut img,
"Copyright 2024",
&fonts,
args.font_size,
args.watermark_position,
args.watermark_color,
)?;
img.save("output.png")?;
The processor::add_watermark implementation uses the alpha channel (128) to blend the watermark text with the underlying image pixels, creating the semi-transparent overlay effect.
Overriding the Default Watermark Color
While the default #FFFFFF80 provides neutral visibility against most backgrounds, you can specify custom RRGGBBAA values via the command line:
# Semi-transparent red watermark
imgkit -i source.jpg -o dest.jpg --watermark-color "#FF000080"
# Fully opaque black watermark
imgkit -i source.jpg -o dest.jpg --watermark-color "#000000FF"
# Semi-transparent blue watermark
imgkit -i source.jpg -o dest.jpg --watermark-color "#0000FF80"
The CLI parser validates the hexadecimal string format and converts it to the internal HexColor(Rgba<u8>) representation before passing it to the processing functions.
Understanding the RRGGBBAA Format Structure
The RRGGBBAA format extends standard RGB hexadecimal notation with an alpha channel:
- RR (Red):
FF(255) = maximum red intensity - GG (Green):
FF(255) = maximum green intensity - BB (Blue):
FF(255) = maximum blue intensity - AA (Alpha):
80(128) = 50% opacity
The alpha value operates on a 0-255 scale where 00 represents fully transparent and FF represents fully opaque. The default value of 80 (128) positions the watermark exactly at midpoint opacity, ensuring visibility without completely obscuring the underlying image content.
Summary
- The default watermark color RRGGBBAA in ImageKit is
#FFFFFF80(white with 50% opacity). - This default is defined in
src/cli.rslines 33-34 within theClistruct asHexColor(Rgba([255, 255, 255, 128])). - The
processor::add_watermarkfunction consumes this value to render semi-transparent text overlays. - Override defaults using the
--watermark-colorCLI argument with any valid RRGGBBAA hex string.
Frequently Asked Questions
What is the default watermark color in RRGGBBAA format?
According to the ImageKit source code in src/cli.rs, the default watermark color is #FFFFFF80. This represents white (RGB 255,255,255) with 50% opacity (alpha 128), providing balanced visibility across varied image backgrounds.
How do I override the default watermark color in ImageKit?
Pass the --watermark-color flag followed by a valid RRGGBBAA hex string when invoking the CLI. For example: imgkit -i input.jpg -o output.jpg --watermark-color "#FF000080" sets a semi-transparent red watermark instead of the default white.
What does the alpha value 128 represent in the default color?
The alpha value 128 (hexadecimal 80) represents 50% opacity on the 0-255 alpha channel scale. This midpoint value ensures the watermark text remains readable while allowing 50% of the underlying image pixels to show through, creating a professional overlay effect.
Which source file contains the default watermark configuration?
The default configuration resides in src/cli.rs within the Cli struct definition. Lines 33-34 instantiate the watermark_color field with HexColor(Rgba([255, 255, 255, 128])), which the CLI parser uses when no --watermark-color argument is provided.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →