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

Availability of aspect ratio validation #19

Closed
enkhtulga opened this issue Jun 25, 2019 · 3 comments
Closed

Availability of aspect ratio validation #19

enkhtulga opened this issue Jun 25, 2019 · 3 comments

Comments

@enkhtulga
Copy link

Thank you for this awesome component. Is there any event before upload image? I want to check image aspect ratio before upload image. For example. If someone try to upload image with aspect ratio 4:2, then it's impossible to upload. Because i set image aspect ratio to 4:3. By the way, I really want to get event before upload image.

Any Suggestion would be greatly appreciated. Thank you

@enkhtulga
Copy link
Author

@svale

@svale
Copy link
Member

svale commented Aug 17, 2019

Hi @enkhtulga. Thank you very much for your patience with my late reply!

There is an notification event triggered as soon as a file is read (@onUpload), but if you need any logic based on the file properties (like the aspect ratio), it seems you would need access to the file data itself.

So what I think what you could use is dimensions/aspec ratio output that lets test for criteria like this. Hope to include that in an update I'll publish this weekend.

@svale
Copy link
Member

svale commented Aug 19, 2019

Ok, so with the latest update (2.1.0), you should be able to check the aspect ratio on your upload.
Basically something like this:

    <image-uploader
      :preview="false"
      outputFormat="verbose"
      @input="onUpload"
    >

Disable the built in preview, set output to verbose and handle the logic in a custom method:

  methods: {
    onUpload: function(image) {
      const aspectRatio = image.info.aspectRatio
      if (aspectRatio !== 1.33) { //4:3
        //abort
        this.upload = false
        alert('Error: Wrong aspect ratio')
      } else {
        // continue
        this.upload = image.dataUrl
      }
    },
  }

Check for any constraints with the info.aspectRatio property (or width/height) and go on from there.

Thank you for the input! Fell free to re-open of this doesn't work as expected.

@svale svale closed this as completed Aug 19, 2019
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