Skip to content Skip to sidebar Skip to footer

What's Default Image Quality In Todataurl?

Here is doc for toDataURL: Syntax canvas.toDataURL(type, encoderOptions); Parameters type Optional A DOMString indicating the image format. The default type is image/png. e

Solution 1:

Blink: 0.92 for JPEG and 0.80 for WEBP.

Gecko: 0.92 for JPEG (no webp support)

How I found it

I searched for "toDataURL" using https://code.google.com/p/chromium/codesearch

Relevant code https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/core/html/HTMLCanvasElement.cpp&q=toDataURL&sq=package:chromium&l=517

Looks like it sets the quality like so double quality = UndefinedQualityValue; where UndefinedQualityValue; is a constant of -1.0.

Following the call chain further down we get to https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/platform/graphics/ImageBuffer.cpp&sq=package:chromium&l=348&rcl=1448382621

bool ImageDataBuffer::encodeImage(constString& mimeType, constdouble& quality, Vector<unsigned char>* encodedImage) const
{
    if (mimeType == "image/jpeg") {
        int compressionQuality = JPEGImageEncoder::DefaultCompressionQuality;
        if (quality >= 0.0 && quality <= 1.0)
            compressionQuality = static_cast<int>(quality * 100 + 0.5);
        if (!JPEGImageEncoder::encode(*this, compressionQuality, encodedImage))
            returnfalse;
    } elseif (mimeType == "image/webp") {
        int compressionQuality = WEBPImageEncoder::DefaultCompressionQuality;
        if (quality >= 0.0 && quality <= 1.0)
            compressionQuality = static_cast<int>(quality * 100 + 0.5);
        if (!WEBPImageEncoder::encode(*this, compressionQuality, encodedImage))
            returnfalse;
    } else {
        if (!PNGImageEncoder::encode(*this, encodedImage))
            returnfalse;
        ASSERT(mimeType == "image/png");
    }

    returntrue;
}

Where the values are as follows:

  • JPEGImageEncoder::DefaultCompressionQuality = 92source
  • WEBPImageEncoder::DefaultCompressionQuality = 80source

Gecko

We can follow a similar process as the above with mozilla code search, or just google "gecko image encoder" which takes you to the following value: JPEG: 0.92 source

Post a Comment for "What's Default Image Quality In Todataurl?"