-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathphotoboxScript.js
81 lines (66 loc) · 1.94 KB
/
photoboxScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* global document */
/*
* grunt-photoBox
* https://github.com/stefan/grunt-photoBox
*
* Copyright (c) 2013 stefan judis
* Licensed under the MIT license.
*/
var system = require ( 'system' ),
webpage = require( 'webpage' ),
fs = require( 'fs' ),
page = webpage.create(),
picture = system.args[ 1 ],
split = picture.split( '#' ),
url = split[ 0 ],
width = +split[ 1 ],
image = split[ 2 ],
indexPath = system.args[ 2 ],
timeOut = 1000,
settings = fs.read( indexPath + 'options.json' );
if ( settings !== '{}' ) {
try {
system.stderr.writeLine( 'Read settings: ' + settings );
settings = JSON.parse( settings );
page.settings = settings;
timeOut = settings.timeOut || timeOut;
} catch( e ) {
console.warn( 'CONSOLE: Error parsing settings | ' + e );
phantom.exit( 1 );
}
}
page.onError = function ( msg ) {
system.stderr.writeLine( 'ERROR:' + msg );
};
page.onConsoleMessage = function( msg, lineNum, sourceId ) {
system.stderr.writeLine( 'CONSOLE: ' + msg, lineNum, sourceId );
};
page.viewportSize = {
height : 1000,
width : width
};
page.open( url, function( status ) {
window.setTimeout( function() {
var height = page.evaluate( function() {
return Math.max(
document.body.scrollHeight, document.documentElement.scrollHeight,
document.body.offsetHeight, document.documentElement.offsetHeight,
document.body.clientHeight, document.documentElement.clientHeight
);
} );
page.clipRect = {
top : 0,
left : 0,
height : height,
width : width
};
var imgPath = indexPath +
'img/current/' +
image +
'-' + width +
'.png';
console.log( 'Rendering ' + picture, width);
page.render( imgPath );
phantom.exit();
}, timeOut );
} );