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

Plugin increases the file size after cropping in ionic .Cropped images are larger than original images #29

Open
tanmaybhatt opened this issue Dec 29, 2015 · 8 comments

Comments

@tanmaybhatt
Copy link

Original file was about 154 kb , after cropping it was 784kb . Another file was about 500kb which turned to 2.2 MB after cropping.
I used Cordova Camera plugin to get the File URI then i fed it to jr Crop function and then i saved it to the storage through File Transfer plugin

@JrSchild
Copy link
Owner

See the examples folder. You should use the toBlob function to turn it into a binary before transferring it. I have used the blueimp polyfill, I plan to shiv it in the future by default. I have not tested it with the File Transfer plugin, but using FormData() should work (also in examples).

Let me know if that worked.

@tanmaybhatt
Copy link
Author

I tired toBlob on android , It says canvas.toBlob is not a function but i found a workaround by reducing resolution through targetWidth and targetHeight in camera plugin.

@JrSchild
Copy link
Owner

To use toBlob on Android you should include the polyfill. But you've found your own workaround.

@tanmaybhatt
Copy link
Author

Thanks Anyways,
Also When i use camera plugin it saves every selected image in cache so when you select image for the second time it overwrites the cache but the changes doesnt reflect in the DOM . So i think you should add some unique value (time in milliseconds) in the src value where you create img tag and add url to source

252  .prop('src', this.options.url+"?t=" + new Date().getTime());

@JrSchild
Copy link
Owner

Ah cachebust! Thank you, I'll close this again when it's fixed.

@JrSchild JrSchild reopened this Dec 30, 2015
@tanmaybhatt
Copy link
Author

Yeah sure... 😄

@JrSchild
Copy link
Owner

JrSchild commented Jan 3, 2016

The problem with your modification is that there are edge cases that I think need to be resolved to do something like this. It will probably break or throw errors when: 1) a user puts base64 data as url, 2) the url already contains a question mark.

@tanmaybhatt
Copy link
Author

Yeah , you are absolutely correct.

I think with base64 data cachebust wont be a problem so no modification is required.
If the url already contains a question mark we can add this variable just after ? as below

var url = this.options.url.split('?');
and use it like
.prop('src', url[0]+"?t=" + new Date().getTime() +"&"+url[1]);

because there must not be more than one question mark in the url and alse there must be some url variables after question mark.
So normally we can have 3 different codes for all 3 conditions.
Its definitely not the best solution but may work.

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