@@ -362,6 +362,7 @@ struct ImageTransformArgs {
362362 brightness : Option < i32 > ,
363363 huerotate : Option < i32 > ,
364364 orientation : Option < Orientation > ,
365+ crop : Option < ( u32 , u32 , u32 , u32 ) > ,
365366}
366367
367368pub struct EncodeTask {
@@ -443,6 +444,9 @@ impl Task for EncodeTask {
443444 if let Some ( hue) = self . image_transform_args . huerotate {
444445 meta. image = meta. image . huerotate ( hue) ;
445446 }
447+ if let Some ( ( x, y, width, height) ) = self . image_transform_args . crop {
448+ meta. image = meta. image . crop_imm ( x, y, width, height) ;
449+ }
446450 let dynamic_image = & mut meta. image ;
447451 let color_type = & meta. color_type ;
448452 let width = dynamic_image. width ( ) ;
@@ -728,6 +732,13 @@ impl Transformer {
728732 self
729733 }
730734
735+ #[ napi]
736+ /// Crop a cut-out of this image delimited by the bounding rectangle.
737+ pub fn crop ( & mut self , x : u32 , y : u32 , width : u32 , height : u32 ) -> & Self {
738+ self . image_transform_args . crop = Some ( ( x, y, width, height) ) ;
739+ self
740+ }
741+
731742 #[ napi]
732743 /// The quality factor `quality_factor` ranges from 0 to 100 and controls the loss and quality during compression.
733744 /// The value 0 corresponds to low quality and small output sizes, whereas 100 is the highest quality and largest output size.
0 commit comments