-
Notifications
You must be signed in to change notification settings - Fork 107
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
automated screenshots with phantomjs and image magick #269
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2767966
First working example with screenshots, cropping and waiting for
hutzelknecht 33428b2
working example for clipping and correct paths
hutzelknecht 05ce1e8
automated screenshots with phantomjs and image magick
hutzelknecht 9ad4c16
Update mappanel_with_actions.js
hutzelknecht fd005df
reuse variable from above
hutzelknecht 5f3a900
for loop formatted for better readability
hutzelknecht 1e52d11
added check for dependent tools and support for calling script from a…
hutzelknecht bd498b4
made the documentation look exactly like on gh-pages branch
hutzelknecht cde489a
moved screenshot scripts to new tools folder; replaced tabs with spaces;
hutzelknecht a0b7492
added line in README about generating screenshots
hutzelknecht File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -166,6 +166,5 @@ Ext.application({ | |
layout: 'fit', | ||
items: [mappanel] | ||
}); | ||
|
||
} | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
var | ||
system = require('system'), | ||
webpage = require('webpage'), | ||
baseUrl = encodeURI(system.args[1]); | ||
toolsFolder = encodeURI(system.args[2]); | ||
|
||
// provide a string or a config object | ||
var examples = [ | ||
"action/mappanel_with_actions.html", | ||
"app/simple/simple.html", | ||
{ | ||
url: "geocoder/geocoder.html", | ||
fn: function(){ | ||
// open the combobox | ||
var cb = Ext.ComponentQuery.query("gx_geocodercombo")[0]; | ||
cb.doQuery('Bonn', true, true); | ||
cb.expand(); | ||
cb.onExpand(); | ||
cb.select(cb.getStore().getAt(1)); | ||
}, | ||
clipRect: { top: 184, left:28, width: 490, height: 390 }, | ||
wait: 2000 | ||
}, | ||
{ | ||
url: "grid/feature-grid.html", | ||
clipRect: { top: 220, left:20, width: 900, height: 400 } | ||
}, | ||
{ | ||
url: "layeropacityslider/layeropacityslider.html", | ||
clipRect: { top: 246, left:20, width: 400, height: 322 } | ||
}, | ||
{ | ||
url:"legendpanel/legendpanel.html", | ||
clipRect: { top: 136, left:20, width: 800, height: 400 } | ||
}, | ||
"mappanel/mappanel.html", | ||
{ | ||
url:"permalink/permalink.html", | ||
clipRect: { top: 550, left: 20, width: 118, height: 90} | ||
}, | ||
{ | ||
url: "popup/popup.html", | ||
fn: function(){ | ||
// open the popup | ||
var map = window.mapPanel.map; | ||
var feature = map.layers[2].features[0]; | ||
map.zoomIn(); | ||
map.controls[4].clickFeature(feature); | ||
}, | ||
clipRect: { top: 286, left: 25, width: 590, height: 359}, | ||
wait: 4000 | ||
}, | ||
{ | ||
url: "printextent/print-extent.html", | ||
clipRect: { top: 179, left: 20, width: 450, height: 284 } | ||
}, | ||
{ | ||
url:"printform/print-form.html", | ||
clipRect: { top: 148, left: 20, width: 700, height: 420 } | ||
}, | ||
{ | ||
url: "printpage/print-page.html", | ||
clipRect: { top: 148, left: 20, width: 700, height: 410 } | ||
}, | ||
{ | ||
url: "printpreview/print-preview.html", | ||
fn: function(){ | ||
// click the preview button | ||
var button = Ext.ComponentQuery.query('button[text="Print..."]')[0]; | ||
button && button.fireHandler(); | ||
}, | ||
clipRect: {top: 148, left: 20, width: 795, height: 532 }, | ||
wait: 10000 | ||
}, | ||
{ | ||
url: "renderer/renderer.html", | ||
clipRect: {top: 208, left: 20, width: 274, height: 204 } | ||
}, | ||
{ | ||
url: "stylegrid/style-grid.html", | ||
clipRect: {top: 179, left: 20, width: 220, height: 200 } | ||
}, | ||
"tree/tree-legend.html", | ||
{ | ||
url: "wfscapabilities/wfscapabilities.html", | ||
clipRect: {top: 148, left: 20, width: 650, height: 300 } | ||
}, | ||
{ | ||
url: "wmscapabilities/wmscapabilities.html", | ||
clipRect: {top: 148, left: 20, width: 650, height: 300 } | ||
}, | ||
{ | ||
url: "zoomchooser/zoomchooser.html", | ||
clipRect: {top: 148, left: 20, width: 600, height: 400 }, | ||
fn: function(){ | ||
// open the combobox | ||
var cb = Ext.ComponentQuery.query('combobox[emptyText="Zoom Level"]')[0]; | ||
cb.expand(); | ||
}, | ||
wait: 8000 | ||
}, | ||
{ | ||
url: "zoomslider/zoomslider.html", | ||
clipRect: {top: 164, left: 20, width: 400, height: 300 } | ||
} | ||
]; | ||
|
||
/** | ||
* Waits for ExtJS to be ready, then executes provided function | ||
* | ||
* @param fun function to execute | ||
*/ | ||
var waitForExtReady = function(p, fun) { | ||
|
||
var me = this; | ||
|
||
console.log('Waiting for ExtJS to be ready...'); | ||
|
||
var readyChecker = window.setInterval(function() { | ||
|
||
var isReady = p.evaluate(function() { | ||
return Ext && Ext.isReady; | ||
}); | ||
|
||
if (isReady) { | ||
console.log('ExtJS is ready.'); | ||
window.clearInterval(readyChecker); | ||
// call the function that waited to be executed | ||
fun.call(me); | ||
} | ||
|
||
}, 2000); | ||
|
||
}; | ||
|
||
/** | ||
* captures a screenshot for a given url | ||
* @param {string} exampleUrl | ||
* @param {int} count | ||
* @param {object} cfg optional config object with the possible parameters: | ||
* - `url` {string} the url to the html file to open in phantomjs | ||
* - `clipRect` {object} an object specifying the position and bounds | ||
* of the screenshot (see phantomjs docs) | ||
* - `fn` {function} the function to execute before taking the screenshot | ||
* - `wait` {int} milliseconds to wait after executing the fn before taking the screenshot | ||
*/ | ||
var capture = function(exampleUrl, ii, cfg){ | ||
|
||
// the page object for phantomjs (see phantomjs docs) | ||
var page = webpage.create(), | ||
// the url to the html file to open in phantomjs | ||
pageUrl = baseUrl + '' + exampleUrl, | ||
// the url to place the thumb image (can be in subfolders) | ||
thumbUrl = toolsFolder + "/../examples/" + exampleUrl.split("/").slice(0, exampleUrl.split("/").length - 1).join("/") + "/", | ||
// image name | ||
image = 'thumb.png', | ||
// time to wait for the tiles in the map to be loaded | ||
timeForTiles = 16000, | ||
// milliseconds to wait after executing the fn before taking the screenshot | ||
timeForFunction = cfg && cfg.wait || 1000, | ||
// time before closing phantomjs | ||
timeForExit = 2000, | ||
// factor for viewport size | ||
f = 8; | ||
|
||
page.viewportSize = { width: 118 * f, height : 90 * f }; | ||
|
||
page.open(pageUrl, function(){ | ||
|
||
waitForExtReady(page, function() { | ||
|
||
window.setTimeout(function(){ | ||
|
||
// hide theme switcher | ||
page.evaluate( function(){ Ext.get("options-toolbar").hide(); }); | ||
|
||
// call optional function | ||
if (cfg && cfg.fn) page.evaluate( cfg.fn ); | ||
|
||
// clip optionally | ||
if (cfg && cfg.clipRect) page.clipRect = cfg.clipRect; | ||
|
||
// the actual snapshot | ||
window.setTimeout(function(){ | ||
page.render( thumbUrl + image ); | ||
console.log( "captured: " + thumbUrl + image ); | ||
}, timeForFunction + 1000); | ||
|
||
// maybe end phantomjs | ||
if ( ii == examples.length - 1 ) { | ||
window.setTimeout(phantom.exit, timeForFunction + timeForExit); | ||
} | ||
|
||
}, timeForTiles); | ||
|
||
}); | ||
|
||
}); | ||
|
||
} | ||
//loop through all examples and capture screenshots | ||
for (var i = 0; i < examples.length; i++) { | ||
|
||
var url = examples[i]; | ||
|
||
// treat object and string configurations separately | ||
if (url instanceof Object) | ||
{ | ||
capture(url.url,i,{ | ||
fn: url.fn || null, | ||
clipRect: url.clipRect || null | ||
}); | ||
} | ||
else | ||
{ | ||
capture(url,i); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
function chkcmd { | ||
which $1 >/dev/null | ||
if [ $? -ne 0 ];then | ||
echo "Program '$1' not found." | ||
exit 1 | ||
fi | ||
} | ||
chkcmd "phantomjs" | ||
chkcmd "convert" | ||
|
||
SCRIPTDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" | ||
exampleUrl=$1 | ||
|
||
echo $SCRIPTDIR | ||
echo $exampleUrl | ||
|
||
# take screenshots - requires phantomjs | ||
phantomjs "$SCRIPTDIR/screenshots.js" $exampleUrl $SCRIPTDIR | ||
|
||
# resize screenshots - requires imagemagick | ||
for THUMB in $(find "$SCRIPTDIR/examples" | grep thumb.png) | ||
do | ||
convert -resize 118X90 $THUMB $THUMB | ||
done |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This won't work. I'll create a follow up PR to adress this.