From e5f0878f9a3cc3e19deefc14f4bcab784354625f Mon Sep 17 00:00:00 2001 From: 5ohue <86558263+5ohue@users.noreply.github.com> Date: Sun, 12 May 2024 19:13:06 +0300 Subject: [PATCH] Add error handling to some functions --- src/wand/magick.rs | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/wand/magick.rs b/src/wand/magick.rs index a0b30b0..07db581 100644 --- a/src/wand/magick.rs +++ b/src/wand/magick.rs @@ -989,18 +989,24 @@ impl MagickWand { /// Resize the image to the specified width and height, using the /// specified filter type. - pub fn resize_image(&self, width: usize, height: usize, filter: FilterType) { - unsafe { - bindings::MagickResizeImage(self.wand, width.into(), height.into(), filter.into()); + pub fn resize_image(&self, width: usize, height: usize, filter: FilterType) -> Result<()> { + match unsafe { + bindings::MagickResizeImage(self.wand, width.into(), height.into(), filter.into()) + } { + MagickTrue => Ok(()), + _ => Err(MagickError("failed to resize image")), } } /// Resize the image to the specified width and height, using the /// 'thumbnail' optimizations which remove a lot of image meta-data with the goal /// of producing small low cost images suited for display on the web. - pub fn thumbnail_image(&self, width: usize, height: usize) { - unsafe { - bindings::MagickThumbnailImage(self.wand, width.into(), height.into()); + pub fn thumbnail_image(&self, width: usize, height: usize) -> Result<()> { + match unsafe { + bindings::MagickThumbnailImage(self.wand, width.into(), height.into()) + } { + MagickTrue => Ok(()), + _ => Err(MagickError("failed to create thumbnail")), } } @@ -1033,9 +1039,12 @@ impl MagickWand { x_resolution: f64, y_resolution: f64, filter: FilterType, - ) { - unsafe { - bindings::MagickResampleImage(self.wand, x_resolution, y_resolution, filter.into()); + ) -> Result<()> { + match unsafe { + bindings::MagickResampleImage(self.wand, x_resolution, y_resolution, filter.into()) + } { + MagickTrue => Ok(()), + _ => Err(MagickError("failed to resample image")), } }