mirror of
https://github.com/neocities/neocities.git
synced 2025-07-01 00:23:26 +02:00
new image screenshot system for #194
This commit is contained in:
parent
06778925e0
commit
df917f3791
3 changed files with 93 additions and 60 deletions
56
files/phantomjs_screenshot.js
Normal file
56
files/phantomjs_screenshot.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
var page = require('webpage').create()
|
||||
var system = require('system')
|
||||
|
||||
var maxTimeout = 15000
|
||||
|
||||
if (system.args.length === 1) {
|
||||
console.log('required args: <siteURL> <outputFilePath>');
|
||||
phantom.exit(1)
|
||||
}
|
||||
|
||||
var address = system.args[1]
|
||||
var outputPath = system.args[2]
|
||||
|
||||
page.viewportSize = { width: 1280, height: 960 }
|
||||
page.clipRect = { top: 0, left: 0, width: 1280, height: 960}
|
||||
|
||||
/*
|
||||
In development, not working yet.
|
||||
|
||||
page.settings.scriptTimeout = 1000
|
||||
|
||||
page.onLongRunningScript = function() {
|
||||
page.stopJavaScript()
|
||||
phantom.exit(4)
|
||||
}
|
||||
*/
|
||||
|
||||
var t = Date.now()
|
||||
|
||||
console.log('Loading ' + address)
|
||||
|
||||
setTimeout(function() {
|
||||
console.log('timeout')
|
||||
phantom.exit(62)
|
||||
}, maxTimeout)
|
||||
|
||||
page.settings.resourceTimeout = maxTimeout
|
||||
|
||||
page.onResourceTimeout = function(e) {
|
||||
console.log(e.errorCode)
|
||||
console.log(e.errorString)
|
||||
console.log(e.url)
|
||||
phantom.exit(3)
|
||||
}
|
||||
|
||||
page.open(address, function(status) {
|
||||
if(status !== 'success') {
|
||||
console.log('failed')
|
||||
phantom.exit(2)
|
||||
}
|
||||
|
||||
page.render(outputPath)
|
||||
console.log('Loading time ' + (Date.now() - t) + ' msec');
|
||||
phantom.exit()
|
||||
})
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue