0

I've looked on many sites including SO and cannot find a reliable method for converting PNG to JPG using just JavaScript.

I tried the following using canvas:

var imageDataJpeg = document.getElementById('pic5-canvas').toDataURL("image/jpeg");

But the resulting image is broken and has no data.

Is there any way to do this?

tfrizzzzz
  • 33
  • 5
  • Maybe the original image is [tainted](https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image), have you took a look at the Dev console? – Teemu Feb 14 '22 at 13:43
  • @BadPiggie I saw that post and it did not work for me. Am I doing something wrong? – tfrizzzzz Feb 14 '22 at 13:49
  • @Teemu nothing seems to show in the console in Firefox. Is there some way to determine if the image is tainted? – tfrizzzzz Feb 14 '22 at 13:49
  • 1
    Please provide a [mcve]. Use the live demo feature (marked with `<>`) in the question editor. – Quentin Feb 14 '22 at 14:10
  • Just read the MDN article I've linked to above. – Teemu Feb 15 '22 at 09:12

0 Answers0