Skip to content

Commit

Permalink
Merge pull request ariya#1 from dhendo/render-buffer-image-quality
Browse files Browse the repository at this point in the history
Added image quality parameter to renderBuffer
  • Loading branch information
peakji committed Jun 25, 2015
2 parents 5164e8d + 49a2f3b commit 38bb488
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
10 changes: 8 additions & 2 deletions examples/snap_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,30 @@ 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) {
if (request.post.url)
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("");
Expand All @@ -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');
Expand Down
4 changes: 2 additions & 2 deletions src/webpage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion src/webpage.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 38bb488

Please sign in to comment.