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

A few potential fixes #13

Closed
ryancramerdesign opened this issue May 25, 2017 · 3 comments · Fixed by #16
Closed

A few potential fixes #13

ryancramerdesign opened this issue May 25, 2017 · 3 comments · Fixed by #16

Comments

@ryancramerdesign
Copy link

ryancramerdesign commented May 25, 2017

Thanks for this Image uploader/resizer. I've been adapting it for another purpose (just the resizing part), and noticed a few things weren't working in my own testing. It looks like all are simple fixes, and just wanted to pass them along:

  • As far as I can tell, the client-side resizing does not come into play at all unless the config.autoRotate option is true. See this conditional. I basically just removed the autoRotate conditional and left everything within it, and it seems to work fine.

  • The config.maxSize option doesn't appear to work as described in the README. It suggests that it is expecting a float like 1.7, but the actual code seems to be expecting something different. I was able to correct it by adjusting the maxSize part of the scaleImage function to the following (though I'm guessing you know something better):

if(this.config.maxSize > 0 && (this.config.maxSize < (canvas.width * canvas.height) / 1000000)) { 
  var mSize = Math.floor(Math.sqrt(this.config.maxSize * ratio) * 1000);
  mWidth = mWidth > 0 ? Math.min(mWidth, mSize) : mSize;
}
  • As far as I can tell, your resizing code works equally well with png and gif files (?), once I replaced the static image/jpeg content-type from the canvas.toDataURL() call with this.currentFile.type at the bottom of the scaleImage function. I changed it to this below, and it appears to be working, though I may be missing something.
var quality = this.currentFile.type == 'image/jpeg' ? this.config.quality : 1.0;
var imageData = canvas.toDataURL(this.currentFile.type, quality);
@rossturner
Copy link
Owner

Thanks a lot, good spot on the resizing not working - poor ownership on my part as I've not updated this repo in years myself and that will have come in from another PR I accepted. Should have reviewed it a bit more rigorously! Same for the maxSize, introduced my someone else. A lesson to be learned in accepting requests without enough review!

Very interesting bonus it works with other image types too :) Suppose it makes sense when the browser can convert the source file into a canvas.

@ryancramerdesign
Copy link
Author

ryancramerdesign commented May 25, 2017 via email

@dpantel
Copy link
Contributor

dpantel commented Jul 18, 2017

Was just coming to point out the maxSize oopsie, but it's already here. Cheers

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

Successfully merging a pull request may close this issue.

3 participants