Skip to content
Advertisement

JavaScript reduce the size and quality of image with based64 encoded code

I have the based64 encoded code of an image. Now I want to reduce the size and quality of the image. How can I do this in JavaScript or jQuery?

Resolve here is the working code : Index.php Here is javascript code which worked form me

JavaScript

Show.php file

JavaScript

Advertisement

Answer

You can use canvas, put image into it, scale it and get image src with new base64 code.

Here’s the function doing that, it returns promise object, as image needs to be loaded (cached) first before drawing canvas out of it and getting its encoded src.

JavaScript

Can be used like this:

JavaScript

here’s the jsfiddle

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement