-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Progressive quality digression to meet max_size requirements. #8
base: master
Are you sure you want to change the base?
Changes from all commits
75053ea
280e32a
3b1d4ba
6beacf2
b2fcd3f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
var path = require('path'); | ||
var async = require('./async'); | ||
var fs = require('fs'); | ||
|
||
/* | ||
* render(input, output, [callback)] | ||
|
@@ -77,14 +78,34 @@ exports._renderImages = function(input, output, images, callback) { | |
document.body.style.zoom = pixelRatio; | ||
}, pixelRatio); | ||
|
||
/* wait a bit then render the image */ | ||
setTimeout(function () { | ||
var filepath = path.join(output, image.name); | ||
page.render(filepath, function() { | ||
exports.onRenderImage(image); | ||
next(); | ||
}); | ||
}, 200); | ||
/* Attempt first render at 100% quality */ | ||
(function attemptRender(quality){ | ||
/* wait a bit then render the image */ | ||
setTimeout(function () { | ||
var filepath = path.join(output, image.name); | ||
page.render(filepath,{quality:quality},function(e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add spaces after each options:
|
||
// Check file size and append to image hash. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe this file uses the |
||
fs.stat(filepath,function(err,stat){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be: |
||
image.size = stat.size; | ||
image.quality = quality; | ||
// If max_size option is set, check it and try again at a lower quality. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comment style |
||
if (exports.max_size && exports.max_size < stat.size) { | ||
if (quality > exports.min_quality) | ||
attemptRender(quality-exports.quality_increment); | ||
else { | ||
image.warn = 'Could not render image under the max_size setting ('+exports.max_size+') without going under the min_quality setting ('+exports.min_quality+').'; | ||
exports.onRenderImage(image); | ||
next(); | ||
} | ||
} else { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Else on the next line. |
||
exports.onRenderImage(image); | ||
next(); | ||
} | ||
}); | ||
}); | ||
}, exports.render_timeout); | ||
})(100); | ||
|
||
}); | ||
}); | ||
}, | ||
|
@@ -121,7 +142,10 @@ function evaluate(page, func) { | |
return page.evaluate(fn); | ||
} | ||
|
||
|
||
exports.max_size; | ||
exports.min_quality = 50; | ||
exports.quality_increment = 5; | ||
exports.render_timeout = 200; | ||
/* | ||
* The splash screens to render as images. | ||
*/ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be
function() {