ctessier / nova-advanced-image-field

🌄 📐 A Laravel Nova advanced image field with cropping and resizing using Vue Advanced Cropper and Intervention Image
https://novapackages.com/packages/ctessier/nova-advanced-image-field
MIT License
100 stars 26 forks source link

add support for specifying a min and max aspect ratio #63

Open takdw opened 3 years ago

takdw commented 3 years ago

Add support for specifying min and max aspect ratio values for cropping

This PR tries to add a functionality that allows users to specify a minimum and maximum range for aspect ratio. This can be useful when you want to allow a varying number of crop aspect ratios. It uses a listener on a CropperJs instance to determine the crop box. I have still kept the existing vue-cropperjs implementation and that is preferred when the user wants a crop of a fixed aspect ratio. It also allows for cropping outside the bounds of the image. The empty space is filled a white (#ffffff) color.

Usage

AdvancedImage::make('Logo', 'logo')->croppable(1); // square crop 1:1
AdvancedImage::make('Logo', 'logo')->croppable(16 / 9); // 16:9 crop ratio
AdvancedImage::make('Logo', 'logo')->croppable(1, 2); // allowed crop ratios are from 1 (1:1) to 2 (2:1)