Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how do you apply a crop on the target buffer? #31

Closed
TroyKomodo opened this issue Jun 21, 2024 · 4 comments
Closed

how do you apply a crop on the target buffer? #31

TroyKomodo opened this issue Jun 21, 2024 · 4 comments

Comments

@TroyKomodo
Copy link

Previously in older versions we used to be able to provide a crop on both the input and output buffer in the resize function.

if i want to take a subsection of a source image and then impose it upon the dest image at a different sub section.

how-to

@TroyKomodo
Copy link
Author

view.set_crop_box(crop)?;

let mut target_view = if resize_dims != output_dims {
	target_image.view_mut().crop(left, top, width, height)?
} else {
	target_image.view_mut()
};

resizer.resize(&view, &mut target_view)?;

@Cykooz
Copy link
Owner

Cykooz commented Jun 21, 2024

In the new version you have to use CroppedImageMut or TypedCroppedImageMut wrapper for destination image.

use fast_image_resize::images::CroppedImageMut;

let mut cropped_dst_image = CroppedImageMut::new(
    &mut dst_image, 
    dst_left, 
    dst_top, 
    dst_width,
    dst_height,
).unwrap();

let mut resizer = fr::Resizer::new();
resizer
    .resize(
        &src_image,
        &mut cropped_dst_image,
        &ResizeOptions::new().crop(src_left, src_top, src_width, src_height),
    )
    .unwrap();

@TroyKomodo
Copy link
Author

I see thank you, is there a difference to applying a crop on the resize options vs submitting a CroppedImage as the source?

@Cykooz
Copy link
Owner

Cykooz commented Jun 21, 2024

ResizeOptions uses f64 type for crop parameters. It allows you to prevent proportions distortion.
Also, cropping with ResizeOptions can use pixels outside the crop box if needed for the convolution process in areas near the edges of the crop box.

@Cykooz Cykooz closed this as completed Jun 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants