From 49a2f3b80e2f397cd378b043af0b500e897e8858 Mon Sep 17 00:00:00 2001 From: David Henderson Date: Wed, 24 Jun 2015 17:10:25 +0100 Subject: [PATCH] Added image quality parameter to renderBuffer --- examples/snap_service.js | 10 ++++++++-- src/webpage.cpp | 4 ++-- src/webpage.h | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/examples/snap_service.js b/examples/snap_service.js index a2893b7bb5..97a34e6860 100644 --- a/examples/snap_service.js +++ b/examples/snap_service.js @@ -13,13 +13,16 @@ if (system.args.length !== 2) { console.log(JSON.stringify(request, null, 4)); var url = null, - format = 'png'; + format = 'png', + quality = -1; if (request.query) { if (request.query.url) url = request.query.url; if (request.query.format) format = request.query.format; + if (request.query.quality) + quality = request.query.quality *1; } if (request.post) { @@ -27,10 +30,13 @@ if (system.args.length !== 2) { url = request.post.url; if (request.post.format) format = request.post.format; + if (request.post.quality) + quality = request.post.quality *1; } console.log("URL:", url); console.log("Format:", format); + console.log("Quality:", quality); if (!url || url.length == 0) { response.write(""); @@ -47,7 +53,7 @@ if (system.args.length !== 2) { page.open(url, function start(status) { // Buffer is an Uint8ClampedArray - var buffer = page.renderBuffer(format); + var buffer = page.renderBuffer(format, quality); response.statusCode = 200; response.setEncoding('binary'); diff --git a/src/webpage.cpp b/src/webpage.cpp index 8a38b57f92..3a215c24c6 100644 --- a/src/webpage.cpp +++ b/src/webpage.cpp @@ -1019,7 +1019,7 @@ QString WebPage::renderBase64(const QByteArray &format) return ""; } -QByteArray WebPage::renderBuffer(const QByteArray &format) +QByteArray WebPage::renderBuffer(const QByteArray &format, const int quality) { QByteArray nformat = format.toLower(); @@ -1033,7 +1033,7 @@ QByteArray WebPage::renderBuffer(const QByteArray &format) buffer.open(QIODevice::WriteOnly); // Writing image to the buffer, using PNG encoding - rawPageRendering.save(&buffer, nformat); + rawPageRendering.save(&buffer, nformat, quality); return bytes; } diff --git a/src/webpage.h b/src/webpage.h index a17c274edf..81b9e77962 100644 --- a/src/webpage.h +++ b/src/webpage.h @@ -276,7 +276,7 @@ public slots: * @return Rendering base-64 encoded of the page if the given format is supported, otherwise an empty string */ QString renderBase64(const QByteArray &format = "png"); - QByteArray renderBuffer(const QByteArray &format = "png"); + QByteArray renderBuffer(const QByteArray &format = "png", const int quality = -1); bool injectJs(const QString &jsFilePath); void _appendScriptElement(const QString &scriptUrl); QObject *_getGenericCallback();