sitemap2png 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +16 -0
- data/Gemfile +5 -0
- data/LICENSE-MIT +22 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/bin/sitemap2png +5 -0
- data/lib/sitemap2png.rb +3 -0
- data/lib/sitemap2png/cli.rb +39 -0
- data/lib/sitemap2png/version.rb +3 -0
- data/middlesite.gemspec +26 -0
- data/vendor/webkit2png +357 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
OGY5MzhiOWFlOWIxYTA0NzhlZjU5YzdiN2Q1YjNmYTYwOGMyZTkyOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
NzBjZDI2NTczMGZmZDViZmM4MzRmNTJhODZiZWU5YWMwZjMxZjVhZQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NzU0ZTYxMGFiNWJjNzMyNDI4NjJiMTI0ZmYwYzA3OGIyMjg0YWRlODhjMWRk
|
10
|
+
MTc0ODY2OTYxMTUxZjlhOTJlMDFhYmQyZDFiOWZjMTFiMzg3MWFlNjAyYjQx
|
11
|
+
OWRhMmUxMGJkYzE3ZWE2Y2FjM2EyOTZkYzEzNzc4NzRhM2M5NmY=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDI0ZTFjNDNlODIwNjczNDJiMjcyNDJhOTlhNmM0MDFkMWI5MmEwY2FkMzk1
|
14
|
+
YmQ3NDIzNTY1NTkxNjA5NzQzYTViYmQzMTNkNWMwMTUyOWQxMWY2N2RkNWJj
|
15
|
+
ZjI4ZmJhOGQ1YjQ4M2FjNGQ4NzA1ZjI2YWY2ZDg1MDYwNWYxMDc=
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE-MIT
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 We Are Interactive
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# sitemap2png
|
2
|
+
|
3
|
+
> Commandline tool to take screenshots of all pages defined through a sitemap.xml in different resolutions.
|
4
|
+
|
5
|
+
*Note: This tool uses [webkit2png](http://www.paulhammond.org/webkit2png/).*
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
```
|
10
|
+
$ gem install sitemap2png
|
11
|
+
```
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
The following tasks are available trough the command line.
|
15
|
+
|
16
|
+
```
|
17
|
+
Commands:
|
18
|
+
```
|
19
|
+
|
20
|
+
## Development
|
21
|
+
|
22
|
+
When developing you can use the given `rake` tasks:
|
23
|
+
|
24
|
+
```
|
25
|
+
$ rake -T
|
26
|
+
rake build # Build sitemap2png-0.1.0.gem into the pkg directory.
|
27
|
+
rake install # Build and install sitemap2png-0.1.0.gem into system gems.
|
28
|
+
rake release # Create tag v0.1.1 and build and push sitemap2png-0.1.0.gem to Rubygems```
|
29
|
+
```
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality.
|
33
|
+
|
34
|
+
1. Fork it
|
35
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
36
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
37
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
38
|
+
5. Create new Pull Request
|
39
|
+
|
40
|
+
## License
|
41
|
+
Copyright (c) 2013 We Are Interactive under the MIT license.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/sitemap2png
ADDED
data/lib/sitemap2png.rb
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
require "thor"
|
2
|
+
require "nokogiri"
|
3
|
+
require "net/http"
|
4
|
+
|
5
|
+
module Sitemap2png
|
6
|
+
class Cli < Thor
|
7
|
+
|
8
|
+
desc "load SITEMAP TARGET", "Load sitemap.xml and take screenshots"
|
9
|
+
method_option :delay, :aliases => "-d", :type => :numeric, :default => 0
|
10
|
+
def load(sitemap, target)
|
11
|
+
basedir = File.dirname(File.dirname(File.dirname(__FILE__)))
|
12
|
+
webkit2png = "#{basedir}/vendor/webkit2png"
|
13
|
+
|
14
|
+
# validate target
|
15
|
+
raise Thor::Error, "Target directory does not exist!" unless Dir.exists?(target)
|
16
|
+
|
17
|
+
begin
|
18
|
+
puts "Loading sitemap..."
|
19
|
+
xml = Net::HTTP.get_response(URI.parse(sitemap)).body
|
20
|
+
rescue Exception=>e
|
21
|
+
raise Thor::Error, "Could not read sitemap!"
|
22
|
+
end
|
23
|
+
|
24
|
+
# validate data
|
25
|
+
doc = Nokogiri::XML(xml)
|
26
|
+
|
27
|
+
puts "Parsing pages..."
|
28
|
+
doc.css('url > loc').each do |node|
|
29
|
+
url = node.text
|
30
|
+
name = File.basename(url, '.*')
|
31
|
+
puts "Taking shots from: #{url}..."
|
32
|
+
[640, 768, 1024, 1600].each do |width|
|
33
|
+
system "#{webkit2png} #{url} --thumb --dir=#{target} --width=#{width} --filename=#{name}-#{width} --delay=#{options[:delay]}"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/middlesite.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sitemap2png/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sitemap2png"
|
8
|
+
spec.version = Sitemap2png::VERSION
|
9
|
+
spec.authors = ["franklin"]
|
10
|
+
spec.email = ["franklin@weareinteractive.com"]
|
11
|
+
spec.description = %q{Commandline tool to take screenshots of all pages defined through a sitemap.xml in different resolutions.}
|
12
|
+
spec.summary = %q{Takes screenshots of all pages defined in a sitemap.xml.}
|
13
|
+
spec.homepage = "https://github.com/weareinteractive/gem-sitemap2png"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "thor"
|
22
|
+
spec.add_runtime_dependency "nokogiri"
|
23
|
+
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "bundler"
|
26
|
+
end
|
data/vendor/webkit2png
ADDED
@@ -0,0 +1,357 @@
|
|
1
|
+
#!/usr/bin/python
|
2
|
+
|
3
|
+
# webkit2png - makes screenshots of web pages
|
4
|
+
# http://www.paulhammond.org/webkit2png
|
5
|
+
|
6
|
+
__version__ = "0.6"
|
7
|
+
|
8
|
+
# Copyright (c) 2004-2013 Paul Hammond
|
9
|
+
#
|
10
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
11
|
+
# of this software and associated documentation files (the "Software"), to deal
|
12
|
+
# in the Software without restriction, including without limitation the rights
|
13
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
14
|
+
# copies of the Software, and to permit persons to whom the Software is
|
15
|
+
# furnished to do so, subject to the following conditions:
|
16
|
+
#
|
17
|
+
# The above copyright notice and this permission notice shall be included in
|
18
|
+
# all copies or substantial portions of the Software.
|
19
|
+
#
|
20
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
21
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
22
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
23
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
24
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
25
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
26
|
+
# THE SOFTWARE.
|
27
|
+
#
|
28
|
+
|
29
|
+
import sys
|
30
|
+
import optparse
|
31
|
+
|
32
|
+
try:
|
33
|
+
import Foundation
|
34
|
+
import WebKit
|
35
|
+
import AppKit
|
36
|
+
import objc
|
37
|
+
except ImportError:
|
38
|
+
print "Cannot find pyobjc library files. Are you sure it is installed?"
|
39
|
+
sys.exit()
|
40
|
+
|
41
|
+
class AppDelegate (Foundation.NSObject):
|
42
|
+
# what happens when the app starts up
|
43
|
+
def applicationDidFinishLaunching_(self, aNotification):
|
44
|
+
webview = aNotification.object().windows()[0].contentView()
|
45
|
+
webview.frameLoadDelegate().getURL(webview)
|
46
|
+
self.performSelector_withObject_afterDelay_( "timeout:", None, 60 )
|
47
|
+
|
48
|
+
def timeout_(self, obj):
|
49
|
+
Foundation.NSLog("timed out!")
|
50
|
+
AppKit.NSApplication.sharedApplication().terminate_(None)
|
51
|
+
|
52
|
+
class WebkitLoad (Foundation.NSObject, WebKit.protocols.WebFrameLoadDelegate):
|
53
|
+
|
54
|
+
# what happens if something goes wrong while loading
|
55
|
+
def webView_didFailLoadWithError_forFrame_(self,webview,error,frame):
|
56
|
+
print " ... something went wrong: "+error.localizedDescription()
|
57
|
+
self.getURL(webview)
|
58
|
+
|
59
|
+
def webView_didFailProvisionalLoadWithError_forFrame_(self,webview,error,frame):
|
60
|
+
print " ... something went wrong: "+error.localizedDescription()
|
61
|
+
self.getURL(webview)
|
62
|
+
|
63
|
+
def makeFilename(self,URL,options):
|
64
|
+
# make the filename
|
65
|
+
if options.filename:
|
66
|
+
filename = options.filename
|
67
|
+
elif options.md5:
|
68
|
+
try:
|
69
|
+
import md5
|
70
|
+
except ImportError:
|
71
|
+
print "--md5 requires python md5 library"
|
72
|
+
AppKit.NSApplication.sharedApplication().terminate_(None)
|
73
|
+
filename = md5.new(URL).hexdigest()
|
74
|
+
else:
|
75
|
+
import re
|
76
|
+
filename = re.sub('\W','',URL);
|
77
|
+
filename = re.sub('^https?','',filename);
|
78
|
+
if options.datestamp:
|
79
|
+
import time
|
80
|
+
now = time.strftime("%Y%m%d")
|
81
|
+
filename = now + "-" + filename
|
82
|
+
import os
|
83
|
+
dir = os.path.abspath(os.path.expanduser(options.dir))
|
84
|
+
if not os.path.exists(options.dir):
|
85
|
+
os.makedirs(dir)
|
86
|
+
return os.path.join(dir,filename)
|
87
|
+
|
88
|
+
def saveImages(self,bitmapdata,filename,options):
|
89
|
+
# save the fullsize png
|
90
|
+
if options.fullsize:
|
91
|
+
bitmapdata.representationUsingType_properties_(AppKit.NSPNGFileType,None).writeToFile_atomically_(filename + "-full.png",objc.YES)
|
92
|
+
|
93
|
+
if options.thumb or options.clipped:
|
94
|
+
# work out how big the thumbnail is
|
95
|
+
width = bitmapdata.pixelsWide()
|
96
|
+
height = bitmapdata.pixelsHigh()
|
97
|
+
thumbWidth = (width * options.scale)
|
98
|
+
thumbHeight = (height * options.scale)
|
99
|
+
|
100
|
+
# make the thumbnails in a scratch image
|
101
|
+
scratch = AppKit.NSImage.alloc().initWithSize_(
|
102
|
+
Foundation.NSMakeSize(thumbWidth,thumbHeight))
|
103
|
+
scratch.lockFocus()
|
104
|
+
AppKit.NSGraphicsContext.currentContext().setImageInterpolation_(
|
105
|
+
AppKit.NSImageInterpolationHigh)
|
106
|
+
thumbRect = Foundation.NSMakeRect(0.0, 0.0, thumbWidth, thumbHeight)
|
107
|
+
clipRect = Foundation.NSMakeRect(0.0,
|
108
|
+
thumbHeight-options.clipheight,
|
109
|
+
options.clipwidth, options.clipheight)
|
110
|
+
bitmapdata.drawInRect_(thumbRect)
|
111
|
+
thumbOutput = AppKit.NSBitmapImageRep.alloc().initWithFocusedViewRect_(thumbRect)
|
112
|
+
clipOutput = AppKit.NSBitmapImageRep.alloc().initWithFocusedViewRect_(clipRect)
|
113
|
+
scratch.unlockFocus()
|
114
|
+
|
115
|
+
# save the thumbnails as pngs
|
116
|
+
if options.thumb:
|
117
|
+
thumbOutput.representationUsingType_properties_(
|
118
|
+
AppKit.NSPNGFileType,None
|
119
|
+
).writeToFile_atomically_(filename + ".png",objc.YES)
|
120
|
+
if options.clipped:
|
121
|
+
clipOutput.representationUsingType_properties_(
|
122
|
+
AppKit.NSPNGFileType,None
|
123
|
+
).writeToFile_atomically_(filename + "-clipped.png",objc.YES)
|
124
|
+
|
125
|
+
def getURL(self,webview):
|
126
|
+
if self.urls:
|
127
|
+
if self.urls[0] == '-':
|
128
|
+
url = sys.stdin.readline().rstrip()
|
129
|
+
if not url: AppKit.NSApplication.sharedApplication().terminate_(None)
|
130
|
+
else:
|
131
|
+
url = self.urls.pop(0)
|
132
|
+
else:
|
133
|
+
AppKit.NSApplication.sharedApplication().terminate_(None)
|
134
|
+
print "Fetching", url, "..."
|
135
|
+
self.resetWebview(webview)
|
136
|
+
webview.mainFrame().loadRequest_(Foundation.NSURLRequest.requestWithURL_(Foundation.NSURL.URLWithString_(url)))
|
137
|
+
if not webview.mainFrame().provisionalDataSource():
|
138
|
+
print " ... not a proper url?"
|
139
|
+
self.getURL(webview)
|
140
|
+
|
141
|
+
def resetWebview(self,webview):
|
142
|
+
rect = Foundation.NSMakeRect(0,0,self.options.initWidth,self.options.initHeight)
|
143
|
+
window = webview.window()
|
144
|
+
window.setContentSize_((self.options.initWidth,self.options.initHeight))
|
145
|
+
|
146
|
+
if self.options.transparent:
|
147
|
+
window.setOpaque_(objc.NO)
|
148
|
+
window.setBackgroundColor_(AppKit.NSColor.clearColor())
|
149
|
+
webview.setDrawsBackground_(objc.NO)
|
150
|
+
|
151
|
+
webview.setFrame_(rect)
|
152
|
+
|
153
|
+
def captureView(self,view):
|
154
|
+
bounds = view.bounds()
|
155
|
+
if bounds.size.height > self.options.UNSAFE_max_height:
|
156
|
+
print >> sys.stderr, "Error: page height greater than %s, clipping to avoid crashing windowserver." % self.options.UNSAFE_max_height
|
157
|
+
bounds.size.height = self.options.UNSAFE_max_height
|
158
|
+
if bounds.size.width > self.options.UNSAFE_max_width:
|
159
|
+
print >> sys.stderr, "Error: page width greater than %s, clipping to avoid crashing windowserver." % self.options.UNSAFE_max_width
|
160
|
+
bounds.size.width = self.options.UNSAFE_max_width
|
161
|
+
|
162
|
+
view.window().display()
|
163
|
+
view.window().setContentSize_(Foundation.NSSize(bounds.size.width, self.options.initHeight))
|
164
|
+
view.setFrame_(bounds)
|
165
|
+
|
166
|
+
if hasattr(view, "bitmapImageRepForCachingDisplayInRect_"):
|
167
|
+
bitmapdata = view.bitmapImageRepForCachingDisplayInRect_(bounds)
|
168
|
+
view.cacheDisplayInRect_toBitmapImageRep_(bounds, bitmapdata)
|
169
|
+
else:
|
170
|
+
view.lockFocus()
|
171
|
+
bitmapdata = AppKit.NSBitmapImageRep.alloc()
|
172
|
+
bitmapdata.initWithFocusedViewRect_(bounds)
|
173
|
+
view.unlockFocus()
|
174
|
+
return bitmapdata
|
175
|
+
|
176
|
+
# what happens when the page has finished loading
|
177
|
+
def webView_didFinishLoadForFrame_(self,webview,frame):
|
178
|
+
# don't care about subframes
|
179
|
+
if (frame == webview.mainFrame()):
|
180
|
+
if self.options.js:
|
181
|
+
scriptobject = webview.windowScriptObject()
|
182
|
+
scriptobject.evaluateWebScript_(self.options.js)
|
183
|
+
Foundation.NSTimer.scheduledTimerWithTimeInterval_target_selector_userInfo_repeats_( self.options.delay, self, self.doGrab, webview, False)
|
184
|
+
|
185
|
+
def doGrab(self,timer):
|
186
|
+
webview = timer.userInfo()
|
187
|
+
view = webview.mainFrame().frameView().documentView()
|
188
|
+
|
189
|
+
URL = webview.mainFrame().dataSource().initialRequest().URL().absoluteString()
|
190
|
+
filename = self.makeFilename(URL, self.options)
|
191
|
+
|
192
|
+
bitmapdata = self.captureView(view)
|
193
|
+
self.saveImages(bitmapdata,filename,self.options)
|
194
|
+
|
195
|
+
print " ... done"
|
196
|
+
self.getURL(webview)
|
197
|
+
|
198
|
+
|
199
|
+
def main():
|
200
|
+
|
201
|
+
# parse the command line
|
202
|
+
usage = """%prog [options] [http://example.net/ ...]
|
203
|
+
|
204
|
+
Examples:
|
205
|
+
%prog http://google.com/ # screengrab google
|
206
|
+
%prog -W 1000 -H 1000 http://google.com/ # bigger screengrab of google
|
207
|
+
%prog -T http://google.com/ # just the thumbnail screengrab
|
208
|
+
%prog -TF http://google.com/ # just thumbnail and fullsize grab
|
209
|
+
%prog -o foo http://google.com/ # save images as "foo-thumb.png" etc
|
210
|
+
%prog - # screengrab urls from stdin
|
211
|
+
%prog -h | less # full documentation"""
|
212
|
+
|
213
|
+
cmdparser = optparse.OptionParser(usage,version=("webkit2png "+__version__))
|
214
|
+
# TODO: add quiet/verbose options
|
215
|
+
cmdparser.add_option("--debug", action="store_true",
|
216
|
+
help=optparse.SUPPRESS_HELP)
|
217
|
+
|
218
|
+
# warning: setting these too high can crash your window server
|
219
|
+
cmdparser.add_option("--UNSAFE-max-height", type="int",default=30000,
|
220
|
+
help=optparse.SUPPRESS_HELP)
|
221
|
+
cmdparser.add_option("--UNSAFE-max-width", type="int",default=30000,
|
222
|
+
help=optparse.SUPPRESS_HELP)
|
223
|
+
|
224
|
+
group = optparse.OptionGroup(cmdparser, "Browser Window Options")
|
225
|
+
group.add_option("-W", "--width",type="float",default=800.0,
|
226
|
+
help="initial (and minimum) width of browser (default: 800)")
|
227
|
+
group.add_option("-H", "--height",type="float",default=600.0,
|
228
|
+
help="initial (and minimum) height of browser (default: 600)")
|
229
|
+
group.add_option("-z", "--zoom",type="float",default=1.0,
|
230
|
+
help="zoom level of browser, equivalent to \"Zoom In\" and \"Zoom Out\" in \"View\" menu (default: 1.0)")
|
231
|
+
cmdparser.add_option_group(group)
|
232
|
+
|
233
|
+
group = optparse.OptionGroup(cmdparser, "Output size options")
|
234
|
+
group.add_option("-F", "--fullsize", action="store_true",
|
235
|
+
help="only create fullsize screenshot")
|
236
|
+
group.add_option("-T", "--thumb", action="store_true",
|
237
|
+
help="only create thumbnail sreenshot")
|
238
|
+
group.add_option("-C", "--clipped", action="store_true",
|
239
|
+
help="only create clipped thumbnail screenshot")
|
240
|
+
group.add_option("--clipwidth",type="float",default=200.0,
|
241
|
+
help="width of clipped thumbnail (default: 200)",
|
242
|
+
metavar="WIDTH")
|
243
|
+
group.add_option("--clipheight",type="float",default=150.0,
|
244
|
+
help="height of clipped thumbnail (default: 150)",
|
245
|
+
metavar="HEIGHT")
|
246
|
+
group.add_option("-s", "--scale",type="float",default=0.25,
|
247
|
+
help="scale factor for thumbnails (default: 0.25)")
|
248
|
+
cmdparser.add_option_group(group)
|
249
|
+
|
250
|
+
group = optparse.OptionGroup(cmdparser, "Output filename options")
|
251
|
+
group.add_option("-D", "--dir",type="string",default="./",
|
252
|
+
help="directory to place images into")
|
253
|
+
group.add_option("-o", "--filename", type="string",default="",
|
254
|
+
metavar="NAME", help="save images as NAME-full.png,NAME-thumb.png etc")
|
255
|
+
group.add_option("-m", "--md5", action="store_true",
|
256
|
+
help="use md5 hash for filename (like del.icio.us)")
|
257
|
+
group.add_option("-d", "--datestamp", action="store_true",
|
258
|
+
help="include date in filename")
|
259
|
+
cmdparser.add_option_group(group)
|
260
|
+
|
261
|
+
group = optparse.OptionGroup(cmdparser, "Web page functionality")
|
262
|
+
group.add_option("--delay",type="float",default=0,
|
263
|
+
help="delay between page load finishing and screenshot")
|
264
|
+
group.add_option("--js", type="string", default=None,
|
265
|
+
help="JavaScript to execute when the window finishes loading (example: --js='document.bgColor=\"red\";')")
|
266
|
+
group.add_option("--noimages", action="store_true",
|
267
|
+
help=optparse.SUPPRESS_HELP)
|
268
|
+
group.add_option("--no-images", action="store_true",
|
269
|
+
help="don't load images")
|
270
|
+
group.add_option("--nojs", action="store_true",
|
271
|
+
help=optparse.SUPPRESS_HELP)
|
272
|
+
group.add_option("--no-js", action="store_true",
|
273
|
+
help="disable JavaScript support")
|
274
|
+
group.add_option("--transparent", action="store_true",
|
275
|
+
help="render output on a transparent background (requires a web page with a transparent background)", default=False)
|
276
|
+
group.add_option("--user-agent", type="string", default=False,
|
277
|
+
help="set user agent header")
|
278
|
+
cmdparser.add_option_group(group)
|
279
|
+
|
280
|
+
(options, args) = cmdparser.parse_args()
|
281
|
+
if len(args) == 0:
|
282
|
+
cmdparser.print_usage()
|
283
|
+
return
|
284
|
+
if options.filename:
|
285
|
+
if len(args) != 1 or args[0] == "-":
|
286
|
+
print "--filename option requires exactly one url"
|
287
|
+
return
|
288
|
+
|
289
|
+
# deprecated options
|
290
|
+
if options.nojs:
|
291
|
+
print >> sys.stderr, 'Warning: --nojs will be removed in webkit2png 1.0. Please use --no-js.'
|
292
|
+
options.no_js = True
|
293
|
+
if options.noimages:
|
294
|
+
print >> sys.stderr, 'Warning: --noimages will be removed in webkit2png 1.0. Please use --no-images.'
|
295
|
+
options.no_images = True
|
296
|
+
|
297
|
+
if options.scale == 0:
|
298
|
+
cmdparser.error("scale cannot be zero")
|
299
|
+
# make sure we're outputing something
|
300
|
+
if not (options.fullsize or options.thumb or options.clipped):
|
301
|
+
options.fullsize = True
|
302
|
+
options.thumb = True
|
303
|
+
options.clipped = True
|
304
|
+
# work out the initial size of the browser window
|
305
|
+
# (this might need to be larger so clipped image is right size)
|
306
|
+
options.initWidth = (options.clipwidth / options.scale)
|
307
|
+
options.initHeight = (options.clipheight / options.scale)
|
308
|
+
options.width *= options.zoom
|
309
|
+
if options.width>options.initWidth:
|
310
|
+
options.initWidth = options.width
|
311
|
+
if options.height>options.initHeight:
|
312
|
+
options.initHeight = options.height
|
313
|
+
|
314
|
+
options.initWidth = options.width
|
315
|
+
options.initHeight = options.height
|
316
|
+
|
317
|
+
app = AppKit.NSApplication.sharedApplication()
|
318
|
+
|
319
|
+
# create an app delegate
|
320
|
+
delegate = AppDelegate.alloc().init()
|
321
|
+
AppKit.NSApp().setDelegate_(delegate)
|
322
|
+
|
323
|
+
# create a window
|
324
|
+
rect = Foundation.NSMakeRect(0,0,100,100)
|
325
|
+
win = AppKit.NSWindow.alloc()
|
326
|
+
win.initWithContentRect_styleMask_backing_defer_ (rect,
|
327
|
+
AppKit.NSBorderlessWindowMask, 2, 0)
|
328
|
+
if options.debug:
|
329
|
+
win.orderFrontRegardless()
|
330
|
+
# create a webview object
|
331
|
+
webview = WebKit.WebView.alloc()
|
332
|
+
webview.initWithFrame_(rect)
|
333
|
+
# turn off scrolling so the content is actually x wide and not x-15
|
334
|
+
webview.mainFrame().frameView().setAllowsScrolling_(objc.NO)
|
335
|
+
|
336
|
+
if options.user_agent:
|
337
|
+
webview.setCustomUserAgent_(options.user_agent)
|
338
|
+
webview.setPreferencesIdentifier_('webkit2png')
|
339
|
+
webview.preferences().setLoadsImagesAutomatically_(not options.no_images)
|
340
|
+
webview.preferences().setJavaScriptEnabled_(not options.no_js)
|
341
|
+
|
342
|
+
if options.zoom != 1.0:
|
343
|
+
webview._setZoomMultiplier_isTextOnly_(options.zoom, False)
|
344
|
+
|
345
|
+
# add the webview to the window
|
346
|
+
win.setContentView_(webview)
|
347
|
+
|
348
|
+
# create a LoadDelegate
|
349
|
+
loaddelegate = WebkitLoad.alloc().init()
|
350
|
+
loaddelegate.options = options
|
351
|
+
loaddelegate.urls = args
|
352
|
+
webview.setFrameLoadDelegate_(loaddelegate)
|
353
|
+
|
354
|
+
app.run()
|
355
|
+
|
356
|
+
if __name__ == '__main__' : main()
|
357
|
+
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sitemap2png
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- franklin
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-18 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: nokogiri
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ! '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Commandline tool to take screenshots of all pages defined through a sitemap.xml
|
70
|
+
in different resolutions.
|
71
|
+
email:
|
72
|
+
- franklin@weareinteractive.com
|
73
|
+
executables:
|
74
|
+
- sitemap2png
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE-MIT
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- bin/sitemap2png
|
84
|
+
- lib/sitemap2png.rb
|
85
|
+
- lib/sitemap2png/cli.rb
|
86
|
+
- lib/sitemap2png/version.rb
|
87
|
+
- middlesite.gemspec
|
88
|
+
- vendor/webkit2png
|
89
|
+
homepage: https://github.com/weareinteractive/gem-sitemap2png
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ! '>='
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.1.11
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Takes screenshots of all pages defined in a sitemap.xml.
|
113
|
+
test_files: []
|