DEV Community

loading...
Cover image for Creating an Image from HTML Canvas

Creating an Image from HTML Canvas

markmead profile image Mark Updated on ・1 min read

The HTMLCanvasElement.toDataURL() method returns a data URI containing a representation of the image in the format specified by the type parameter (defaults to PNG). The returned image is in a resolution of 96 dpi.

MOZ HTMLCanvasElement.toDataURL()

You can pass two parameters to toDataURL():

  • type
    Takes a string that decides the format of the image - image/jpeg

  • encoderOptions
    Takes a number that sets the quality of the image (defaults to 0.92)

toDataURL('image/jpeg', 1)

Discussion (0)

pic
Editor guide