Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert jpg image to png using javascript

Tags:

javascript

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.

like image 661
mehmood Avatar asked May 16 '12 11:05

mehmood


1 Answers

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:

  1. Load the jpg image from file
  2. Create a canvas of the same size as the jpg
  3. Draw the jpg image covering the whole canvas
  4. Convert canvas to blob (if the image is small enough you can also use to .toDataURL())
  5. Download the blob
like image 110
sazzy4o Avatar answered Nov 04 '22 20:11

sazzy4o