react-easy-crop icon indicating copy to clipboard operation
react-easy-crop copied to clipboard

cropSize in percentage

Open Rastraponovich opened this issue 1 year ago • 4 comments

Hello, Is it possible to specify the CropSize as a percentage rather than in pixels? There is a need to set the size in % due to different screen sizes. if you specify a clear value, the Crop may go beyond the screen, as a result of which the final result will differ from the expected one.

Ideally, I would like to be able to set not only the height and width, but also control the position of the Crop inside the container as a percentage.

Currently, the size calculation occurs before mounting the component into the DOM through hooks and requests to the Window object

Rastraponovich avatar Aug 14 '24 08:08 Rastraponovich

You most probably should use the aspect property. This is the ratio between width and height.

ValentinH avatar Aug 14 '24 09:08 ValentinH

But if I don't set the CropSize then the Crop will not have the required dimensions. Example. In my case, I need the x axis to be 100% and the y axis according to aspectRatio. Now the Crop width without the CropSize parameter is not 100%. maybe I didn't complete something according to the instructions

Rastraponovich avatar Aug 14 '24 09:08 Rastraponovich

The objectFit prop might be what you are looking for. In general, I don't think that the cropSize should be used as it's not responsive. The important thing when cropping is the aspect of the Cropper + the position and the zoom. From these, every possible crop can be represented.

Once the user has selected the cropped area, then you can convert the percentage selection to a specific pixel size with simple maths.

ValentinH avatar Aug 15 '24 04:08 ValentinH

Thanks

Rastraponovich avatar Aug 15 '24 08:08 Rastraponovich