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

issue with cropper source #14

Closed
rinoldsimon opened this issue Aug 7, 2018 · 8 comments
Closed

issue with cropper source #14

rinoldsimon opened this issue Aug 7, 2018 · 8 comments

Comments

@rinoldsimon
Copy link

rinoldsimon commented Aug 7, 2018

when i upload a different image and update the {{#cropper-image source=*thelatestuploadedimageurl* ... }}. the source changes but the previous options are not getting set to the new image.

@rinoldsimon rinoldsimon changed the title issue for the cropper source issue with copper source Aug 8, 2018
@rinoldsimon rinoldsimon changed the title issue with copper source issue with cropper source Aug 8, 2018
@ynotdraw
Copy link
Collaborator

ynotdraw commented Aug 8, 2018

@rinoldsimon could you send me what options you are setting prior to changing the source? There may be some we are missing. There are some properties where we tear down and construct a new Cropper instance completely, so some of those options may be getting lost if we aren't copying things over properly.

@rinoldsimon
Copy link
Author

rinoldsimon commented Aug 8, 2018

hbs

{{#image-cropper
  source=model.profile_photo
  options=(hash
    aspectRatio=1
    viewMode=2
    minContainerWidth=748
    minContainerHeight=400
    ...
    ...
  )  as |cropper|}}
{{/image-cropper}}

I'm using ember-file-upload addon for file uploads
So when i select a image file from my local machine uploadPhoto action will be called where i set source to the new image.
js

uploadPhoto(file) {
  file.readAsDataURL().then((url) => {
    set(model, 'profile_photo', url);
    ...
    ...
  }

In this scenario cropper source is changed to the new image. But the previous cropper options are not available. So i get a different view with different minContainerWidth, minContainerHeight, etc..

According the cropperjs document there is a method replace(url) which Replace the image's src and rebuild the cropper.
How to call the replace(url) method in uploadPhoto action ?

@ynotdraw
Copy link
Collaborator

ynotdraw commented Aug 8, 2018

Right, we are calling replace already here when the source changes: https://github.com/danielthall/ember-cropperjs/blob/master/addon/components/image-cropper.js#L91

I wonder if we're just missing passing additional options after a replace or something. I can dig in a bit more later this evening.

@rinoldsimon
Copy link
Author

rinoldsimon commented Aug 9, 2018

hasSameSize param to true
_cropper.replace(source, true) works. But the image occupies the same space as the previous one. so if the new image is the portraitone it gets expanded to the size of the previous landscape image.

Think this is not the solution

According to the cropperjs doc, It will not rebuilt the cropper and only update the urls of all related images

@rinoldsimon
Copy link
Author

rinoldsimon commented Aug 9, 2018

is the addon uses the latest version of cropperjs ?

@ynotdraw
Copy link
Collaborator

ynotdraw commented Aug 9, 2018

Thanks for digging in more, @rinoldsimon. Could you try using the branch at https://github.com/danielthall/ember-cropperjs/tree/replace-hasSameSize-fix and let me know if this resolves the issue for you?

You'll just need to add the following to your image-cropper:

{{#image-cropper
  replaceHasSameSize=true
  .
  .

I have an open issue for upgrading to the latest version of cropperjs. It looks like replace with the sameSize option is supported in the version we are using though. If this doesn't work, I'll upgrade to the latest version of cropperjs and try again.

@rinoldsimon
Copy link
Author

I forgot to add this rule.

img {
  max-width: 100%;
}

adding the above rule fixes the issue

@ynotdraw
Copy link
Collaborator

@rinoldsimon glad you got it figured out!

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