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

UserCrop and MaxDimensions #18

Open
rtpHarry opened this issue Sep 12, 2016 · 1 comment
Open

UserCrop and MaxDimensions #18

rtpHarry opened this issue Sep 12, 2016 · 1 comment

Comments

@rtpHarry
Copy link
Contributor

What I expected usercrop to do was let you crop it out to a certain aspect ratio and then it will resize that crop to your preferred size.

Instead of getting my 800x600 image where the user has set the focus of the crop I get a user cropped image that is in 800x600 ratio but could actually be a lot larger like 1335x1000.

I'm not sure if it's implemented wrong or if there should be an extra setting for it which say "and then resize it to this size".

@rtpHarry
Copy link
Contributor Author

rtpHarry commented Sep 13, 2016

To fix this you would just add a few lines to the user crop. I will do a PR depending on how the discussion goes but the code will look something like this:

                    case ResizeActions.UserCrop:
                        // clamp dimensions to prevent overflow caused when some aspect ratios
                        // result in the integer rounding up and ending up bigger than the original canvas
                        viewModel.CropedWidth =
                            viewModel.Coordinates.x + viewModel.CropedWidth > image.Width
                                ? image.Width - viewModel.Coordinates.x
                                : viewModel.CropedWidth;

                        viewModel.CropedHeight =
                            viewModel.Coordinates.y + viewModel.CropedHeight > image.Height
                                ? image.Height - viewModel.Coordinates.y
                                : viewModel.CropedHeight;

                        target = _imageService.Crop(
                            image,
                            new Point(viewModel.Coordinates.x, viewModel.Coordinates.y),
                            viewModel.CropedWidth,
                            viewModel.CropedHeight);

                        // new code
                        if(maxDimensions.Height > 0 & maxDimensions.Width > 0) {
                            target = _imageService.Resize(target, maxDimensions, ResizeType.IgnoreRatio);
                        }
                        // new code

                        newDimensions = new Dimensions(target.Width, target.Height);

                        Services.Notifier.Information(T("The image {0} has been cropped to {1}x{2}",
                            field.Name.CamelFriendly(), newDimensions.Width, newDimensions.Height));

                        break;

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

1 participant