Add metadata stripping, watermark positioning, and rename template modules
This commit is contained in:
31
pixstrip-core/src/operations/watermark.rs
Normal file
31
pixstrip-core/src/operations/watermark.rs
Normal file
@@ -0,0 +1,31 @@
|
||||
use crate::types::Dimensions;
|
||||
use super::WatermarkPosition;
|
||||
|
||||
pub fn calculate_position(
|
||||
position: WatermarkPosition,
|
||||
image_size: Dimensions,
|
||||
watermark_size: Dimensions,
|
||||
margin: u32,
|
||||
) -> (u32, u32) {
|
||||
let iw = image_size.width;
|
||||
let ih = image_size.height;
|
||||
let ww = watermark_size.width;
|
||||
let wh = watermark_size.height;
|
||||
|
||||
let center_x = (iw - ww) / 2;
|
||||
let center_y = (ih - wh) / 2;
|
||||
let right_x = iw - ww - margin;
|
||||
let bottom_y = ih - wh - margin;
|
||||
|
||||
match position {
|
||||
WatermarkPosition::TopLeft => (margin, margin),
|
||||
WatermarkPosition::TopCenter => (center_x, margin),
|
||||
WatermarkPosition::TopRight => (right_x, margin),
|
||||
WatermarkPosition::MiddleLeft => (margin, center_y),
|
||||
WatermarkPosition::Center => (center_x, center_y),
|
||||
WatermarkPosition::MiddleRight => (right_x, center_y),
|
||||
WatermarkPosition::BottomLeft => (margin, bottom_y),
|
||||
WatermarkPosition::BottomCenter => (center_x, bottom_y),
|
||||
WatermarkPosition::BottomRight => (right_x, bottom_y),
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user