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

cropped image results in bigger filesize #98

Closed
Haititi opened this issue Nov 25, 2019 · 5 comments
Closed

cropped image results in bigger filesize #98

Haititi opened this issue Nov 25, 2019 · 5 comments

Comments

@Haititi
Copy link

Haititi commented Nov 25, 2019

Hi (again) !

I have another problem which concerns the image cropping functionnality.
Actually, when i crop an image via your file-manager, the resulted file size of the image is way bigger than the original one, even if the image size is smaller.

I did some research, and actually found the problem here :
https://github.com/alexusmai/vue-laravel-file-manager/blob/de26565b6f47d3c94e32decdb27f79f8ac8b7df5/src/components/modals/additions/Cropper.vue#L247

The "toBlob()" API here is generating the image in "image/png" format by default.
see API doc here : HTMLCanvasElement.toBlob() API

This API takes 3 arguments. If you give the image format "image/jpeg" as 2nd argument, the generated image filesize would be smaller.
The 3rd argument is the quality, but the default value (0.92) seems to be the best one here. I tried to put 100% quality, but the filesize increased a lot.

This fix would be pretty fast. Would it be possible to update your code to save the cropped image in image/jpeg format ?

thanks a lot for your help.

@alexusmai
Copy link
Owner

Hi,

Yes, I did not pay attention to file size after cropping, and forgot about the second parameter for function.
I can do something like this:

this.cropper.getCroppedCanvas().toBlob(
        (blob) => {
         // some code
        },
        this.selectedItem.extension !== 'jpg'
          ? `image/${this.selectedItem.extension}`
          : 'image/jpeg',
      );

This decision will help for cropping jpeg files, they will not be treated as 'image/png' files. But it will not help for cropping png files, they size will stay bigger.

@Haititi
Copy link
Author

Haititi commented Nov 28, 2019

That would be perfect for me !
In any case, only image/jpeg and image/png are supported, and if an invalid one is given, image/png will be used.

All good for me, waiting your realease 😊

@Haititi
Copy link
Author

Haititi commented Dec 3, 2019

Any news about it?
As the fix was already decided and fast to apply, i hope you didnt discover any problem with it.

@alexusmai
Copy link
Owner

Done.

@Haititi
Copy link
Author

Haititi commented Dec 3, 2019

thank you !!
keep doing your amazing work!
I tested other file-manager and yours is just the best one i found 🥇

@Haititi Haititi closed this as completed Dec 3, 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