Convert JPG image to PNG
I have to convert a jpg image into png image using javascript and resize the image to create a thumbnail of image.
Convert JPG image to PNG
I have to convert a jpg image into png image using javascript and resize the image to create a thumbnail of image.
If we have a look at the source from the JPG to PNG website which uses pure javascript to convert images from JPG to PNG. We see that they:
.toDataURL())you should take a look at processing.js library: http://processingjs.org/reference/PImage_resize_/ http://processingjs.org/reference/save_/
It's not impossible to write a pure JavaScript library that allows you to manipulate and convert images, but I don't know any off the top of my head, nor would I use them.
Instead, I'd upload the original image to a server framework of my choice (PHP, ASP.NET, etc.) and have it manipulate the image for you.
There are plenty ports of native png/JPEG libraries through emscripten and also a couple written purely in JavaScript, This is what it comes to my mind now:
https://www.npmjs.com/package/jimp
Jimp.read('lenna.png', (err, lenna) => {
if (err) throw err;
lenna
.write('lena-small-bw.jpg'); // save
});
But in general you want to search something like 'png to jpeg' in npm.org you will find plenty libraries.