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

[Question]: Set Zoom for the cropper on initilization #182

Closed
saadsaeed01 opened this issue Jul 26, 2023 · 4 comments
Closed

[Question]: Set Zoom for the cropper on initilization #182

saadsaeed01 opened this issue Jul 26, 2023 · 4 comments
Labels
good first issue Good for newcomers question Further information is requested

Comments

@saadsaeed01
Copy link

saadsaeed01 commented Jul 26, 2023

Hi

I have an issue that I wanted to discuss related to setting up the initial Zoom

Let's say when I upload the image the initial state of the cropper is this

image

Now without Zooming in or Zooming out, I change the position of the crop window and save my entity
image

If I now save my card the position of the cropper window will persist. The image below shows the position of the cropper window when I save my card and visit the page again
image

Problem
If I Zoom out or Zoom In in the cropper like this and save the entity
image

The zoom is not persisted. Check what happened below
image

I am saving the following Meta Information

  • Height
  • Width
  • ScaleX
  • ScaleY
  • X
  • Y
  • Rotate
  • OldRatio (Fetched from OnZoomEvent)
  • Ratio (Fetched from OnZoomEvent)

On initializing the cropper, I set the non-zoom properties like this in SetDataOptions
image

And I set the zoom properties by calling the ZoomTo method
image

Is there a special way to set the zoom of the canvas, unfortunately, I am not very clear about this. Waiting for your response

I am using Blazor Server NET 6 and the package version is 1.2.4 which is the latest stable

Thank you very much!

Regards
Saad

@MaxymGorn
Copy link
Member

Hi @saadsaeed01. I suppose this option only available when the autoCrop option had set to the true, see official documentation: https://github.com/fengyuanchen/cropperjs#data

@saadsaeed01
Copy link
Author

saadsaeed01 commented Jul 26, 2023

Hi @MaxymGorn
I have set AutoCrop to true but this is not working. Please see the image
image

@MaxymGorn
Copy link
Member

MaxymGorn commented Jul 26, 2023

@saadsaeed01 You can try to use Zoom or ZoomTo, for example in OnCropReadyEvent, because OnAfterRender method cropper component can't be able/ready to receive and perform commands
image
image
I might that can help you!
And data on how much you need to zoom in or zoom out can be obtained from OnZoomEvent
image
image

Although, you need to save zoom ratio

@MaxymGorn MaxymGorn added the question Further information is requested label Jul 26, 2023
@saadsaeed01
Copy link
Author

Hi @MaxymGorn

Check out this solution, Hopefully, this will help other developers too. This is achieved using OnReadyEvent

image

Thank you for your valuable input :)

Regards
S

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants