mocoso-snapurl 0.0.3-universal-darwin
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/History.txt +11 -0
- data/MIT-LICENSE +27 -0
- data/Manifest.txt +10 -0
- data/README.rdoc +62 -0
- data/Rakefile +44 -0
- data/VERSION.yml +4 -0
- data/bin/snapurl +7 -0
- data/lib/core/application.rb +96 -0
- data/lib/core/camera.rb +225 -0
- data/lib/snapurl.rb +28 -0
- data/test/test_snapurl.rb +0 -0
- data/thirdparty/RubyCocoa-0.13.2.tgz +0 -0
- metadata +69 -0
data/.gitignore
ADDED
data/History.txt
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Copyright (c) 2008 Juris Galang
|
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
|
+
Except as contained in this notice, the name(s) of the above
|
16
|
+
copyright holders shall not be used in advertising or otherwise to
|
17
|
+
promote the sale, use or other dealings in this Software without
|
18
|
+
prior written authorization.
|
19
|
+
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
21
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
22
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
23
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
24
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
25
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
26
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
27
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
data/Manifest.txt
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
= snapurl
|
2
|
+
|
3
|
+
* http://www.jurisgalang.com/articles/show/SnapUrl
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
This is a Ruby/RubyCocoa port of the webkit2png.py script by Paul Hammond
|
8
|
+
(http://www.paulhammond.org/webkit2png/) with some minor modifications.
|
9
|
+
|
10
|
+
== FEATURES/PROBLEMS:
|
11
|
+
|
12
|
+
* OS X only.
|
13
|
+
* Requires RubyCocoa (Leopard will already have this installed)
|
14
|
+
* Requires Ruby 1.8.7 (Ruby 1.9.x wont play with RubyCocoa)
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
Just pass a list of URLs to the snapurl script and it will take a snapshot of the pages found in those URLs:
|
19
|
+
|
20
|
+
$ snapurl http://artists.gawker.com/ # takes a snapshot of gawker artists
|
21
|
+
$ snapurl http://io9.com/ http://artists.gawker.com/ # ... and io9 websites.
|
22
|
+
|
23
|
+
By default snapurl generates a set of files per URL that it processes: thumbnail, clipped, and full sized
|
24
|
+
view of the web pages in PNG format.
|
25
|
+
|
26
|
+
== REQUIREMENTS:
|
27
|
+
|
28
|
+
* OS X
|
29
|
+
* Ruby 1.8.7
|
30
|
+
* RubyCocoa
|
31
|
+
|
32
|
+
== BUILD AND INSTALL:
|
33
|
+
|
34
|
+
* sudo rake install_cocoa
|
35
|
+
* rake gemspec
|
36
|
+
* rake build
|
37
|
+
* rake install
|
38
|
+
|
39
|
+
== LICENSE:
|
40
|
+
|
41
|
+
(The MIT License)
|
42
|
+
|
43
|
+
Copyright (c) 2009 FIX
|
44
|
+
|
45
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
46
|
+
a copy of this software and associated documentation files (the
|
47
|
+
'Software'), to deal in the Software without restriction, including
|
48
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
49
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
50
|
+
permit persons to whom the Software is furnished to do so, subject to
|
51
|
+
the following conditions:
|
52
|
+
|
53
|
+
The above copyright notice and this permission notice shall be
|
54
|
+
included in all copies or substantial portions of the Software.
|
55
|
+
|
56
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
57
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
58
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
59
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
60
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
61
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
62
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
$:.unshift File::join(File::dirname(__FILE__), 'lib')
|
4
|
+
|
5
|
+
require 'rubygems'
|
6
|
+
require './lib/snapurl.rb'
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'jeweler'
|
10
|
+
Jeweler::Tasks.new do |gemspec|
|
11
|
+
gemspec.name = "mocoso-snapurl"
|
12
|
+
gemspec.summary = "Render HTML to PNG using WebKit"
|
13
|
+
gemspec.description = "This is a Ruby/RubyCocoa port of the webkit2png.py script by Paul Hammond"
|
14
|
+
gemspec.description += "* (http://www.paulhammond.org/webkit2png/) with some minor modifications."
|
15
|
+
gemspec.platform = "universal-darwin"
|
16
|
+
gemspec.requirements << "Mac OS X 10.5 or later"
|
17
|
+
gemspec.requirements << "RubyCocoa"
|
18
|
+
gemspec.email = 'joel.chippindale@gmail.com'
|
19
|
+
gemspec.authors = ['Juris Galang', 'Joel Chippindale']
|
20
|
+
end
|
21
|
+
Jeweler::GemcutterTasks.new
|
22
|
+
rescue LoadError
|
23
|
+
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
|
24
|
+
end
|
25
|
+
|
26
|
+
desc "Remove additional work directories for build."
|
27
|
+
task :clean do
|
28
|
+
sh "rm -rf tmp"
|
29
|
+
end
|
30
|
+
|
31
|
+
desc "Installs RubyCocoa (you only need to do this once)"
|
32
|
+
task :install_cocoa => :clean do
|
33
|
+
fail "RubyCocoa might not work for Ruby version > 1.8.7, you are using version #{RUBY_VERSION}" unless RUBY_VERSION <= "1.8.7"
|
34
|
+
RUBYCOCOA = "RubyCocoa-0.13.2"
|
35
|
+
sh "mkdir -p tmp && tar zxf thirdparty/#{RUBYCOCOA}.tgz -C tmp"
|
36
|
+
Dir.chdir("tmp/#{RUBYCOCOA}") do
|
37
|
+
sh "ruby install.rb config"
|
38
|
+
sh "ruby install.rb setup"
|
39
|
+
sh "ruby install.rb install"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
# vim: syntax=Ruby
|
data/VERSION.yml
ADDED
data/bin/snapurl
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
=begin
|
2
|
+
* Name: SnapUrl
|
3
|
+
* Description:
|
4
|
+
* This is a Ruby/RubyCocoa port of the webkit2png.py script by Paul Hammond
|
5
|
+
* (http://www.paulhammond.org/webkit2png/) with some minor modifications.
|
6
|
+
* Author: Juris Galang (http://www.JurisGalang.com)
|
7
|
+
* Date: 09/15/08
|
8
|
+
* License:
|
9
|
+
=end
|
10
|
+
module SnapUrl
|
11
|
+
class Application
|
12
|
+
def Application::run(args)
|
13
|
+
config = Application.parse(args)
|
14
|
+
Camera::snap(config[:urls], config[:options])
|
15
|
+
end
|
16
|
+
|
17
|
+
# TODO: add option to control log-level
|
18
|
+
# TODO: add implementation for verbose run
|
19
|
+
# TODO: set --include-format = true if more than one format
|
20
|
+
def Application::parse(args)
|
21
|
+
options = Camera::DEFAULT_OPTIONS
|
22
|
+
begin
|
23
|
+
opts = OptionParser.new do |opts|
|
24
|
+
opts.banner = <<-EOF
|
25
|
+
Usage: #{opts.program_name} url0 [url1] [url2]... [options]
|
26
|
+
|
27
|
+
#{opts.program_name} is a command line tool that creates PNG screenshots of webpages.
|
28
|
+
With tall or wide pages that would normally require scrolling, it takes
|
29
|
+
screenshots of the whole webpage, not just the area that would be visible
|
30
|
+
in a browser window.
|
31
|
+
|
32
|
+
It is a Ruby/RubyCocoa port of the webkit2png.py script by Paul Hammond
|
33
|
+
(http://www.paulhammond.org/webkit2png/)
|
34
|
+
EOF
|
35
|
+
opts.banner.gsub!(/ /, '')
|
36
|
+
|
37
|
+
opts.separator ' '
|
38
|
+
opts.separator 'Specific Options:'
|
39
|
+
opts.on('--width [WIDTH]', Float, "initial and minimum browser width (default: #{options[:browser][:width].to_i})") { |n| options[:browser][:width] = n }
|
40
|
+
opts.on('--height [HEIGHT]', Float, "initial and minimum browser height (default: #{options[:browser][:height].to_i})") { |n| options[:browser][:height] = n }
|
41
|
+
|
42
|
+
opts.separator ' '
|
43
|
+
opts.on('--[no-]fullsize', "create fullsize screenshot") { |n| n ? options[:snapFormat] << :fullsize : options[:snapFormat].delete(:fullsize) }
|
44
|
+
opts.on('--[no-]thumbnail', "create thumbnail") { |n| n ? options[:snapFormat] << :thumbnail : options[:snapFormat].delete(:thumbnail) }
|
45
|
+
opts.on('--[no-]clip', "create clip of thumbnail") { |n| n ? options[:snapFormat] << :clip : options[:snapFormat].delete(:clip) }
|
46
|
+
|
47
|
+
opts.separator ' '
|
48
|
+
opts.on('--scale [SCALE]', Float, "scale factor for thumbnails (default: #{options[:scaleFactor]})") { |n| options[:scaleFactor] = n }
|
49
|
+
|
50
|
+
opts.separator ' '
|
51
|
+
opts.on('--clipwidth [WIDTH]', Float, "width of clipped thumbnail (default: #{options[:clip][:width].to_i})") { |n| options[:clip][:width] = n }
|
52
|
+
opts.on('--clipheight [HEIGHT]', Float, "height of clipped thumbnail (default: #{options[:clip][:height].to_i})") { |n| options[:clip][:height] = n }
|
53
|
+
|
54
|
+
opts.separator ' '
|
55
|
+
opts.on('-f', '--filename [NAME]', "use NAME as part of filename (derived from url if not specified)") { |n| options[:filename] = n }
|
56
|
+
|
57
|
+
opts.on('--use-md5hash', "use md5 hash for filename (overriden by --filename)") { |n| options[:useHashForFilename?] = n }
|
58
|
+
opts.on('--include-datestamp', "include date in filename") { |n| options[:datestampInFilename?] = n }
|
59
|
+
opts.on('--include-timestamp', "include time in filename") { |n| options[:timestampInFilename?] = n }
|
60
|
+
opts.on('--include-size', "include image size in filename") { |n| options[:sizeInFilename?] = n }
|
61
|
+
opts.on('--include-format', "include image format in filename") { |n| options[:snapFormatInFilename?] = n }
|
62
|
+
|
63
|
+
opts.separator ' '
|
64
|
+
opts.on('-d', '--output-dir [DIRNAME]', "directory to place images into (default: #{options[:outputDirectory]})") { |n| options[:outputDirectory] = n }
|
65
|
+
|
66
|
+
opts.separator ' '
|
67
|
+
opts.separator 'Common Options:'
|
68
|
+
opts.on('-v', "--[no-]verbose", "Run verbosely") { |n| options[:verbose?] = n }
|
69
|
+
opts.on_tail("-h", "--help", "Show this message") do
|
70
|
+
puts opts.help
|
71
|
+
exit
|
72
|
+
end
|
73
|
+
|
74
|
+
opts.on_tail("--version", "Show version") do
|
75
|
+
puts opts.ver
|
76
|
+
exit
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
urls = opts.permute!(args)
|
81
|
+
|
82
|
+
raise OptionParser::MissingArgument.new('you need to supply at least one URL') if urls.empty?
|
83
|
+
raise OptionParser::InvalidArgument.new('you can only use the filename option if there is only one URL') if (urls.size > 1) && !options[:filename].empty?
|
84
|
+
raise OptionParser::InvalidArgument.new('scale cannot be zero') if options[:scaleFactor] < 0.0
|
85
|
+
# width and height cannot be zero or less than minimum
|
86
|
+
# clipwidth and clipheight cannot be zero or less than minimum
|
87
|
+
raise OptionParser::AmbiguousArgument.new('you need to allow at least one format') if options[:snapFormat].empty?
|
88
|
+
|
89
|
+
return { :urls => urls, :options => options }
|
90
|
+
rescue OptionParser::ParseError => e
|
91
|
+
puts "#{e.message.capitalize}"
|
92
|
+
exit(1)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
data/lib/core/camera.rb
ADDED
@@ -0,0 +1,225 @@
|
|
1
|
+
=begin
|
2
|
+
* Name: SnapUrl
|
3
|
+
* Description:
|
4
|
+
* This is a Ruby/RubyCocoa port of the webkit2png.py script by Paul Hammond
|
5
|
+
* (http://www.paulhammond.org/webkit2png/) with some minor modifications.
|
6
|
+
* Author: Juris Galang (http://www.JurisGalang.com)
|
7
|
+
* Date: 09/15/08
|
8
|
+
* License:
|
9
|
+
=end
|
10
|
+
|
11
|
+
module SnapUrl
|
12
|
+
module Camera
|
13
|
+
DEFAULT_OPTIONS = {
|
14
|
+
:browser => {:width => 800.0, :height => 600.0},
|
15
|
+
:clip => {:width => 200.0, :height => 150.0},
|
16
|
+
:snapFormat => [:fullsize, :thumbnail, :clip],
|
17
|
+
:scaleFactor => 0.25,
|
18
|
+
:filename => '',
|
19
|
+
:datestampInFilename? => false,
|
20
|
+
:timestampInFilename? => false,
|
21
|
+
:sizeInFilename? => false,
|
22
|
+
:snapFormatInFilename? => false,
|
23
|
+
:useHashForFilename? => false,
|
24
|
+
:outputDirectory => Dir.pwd,
|
25
|
+
:verbose? => false
|
26
|
+
}
|
27
|
+
|
28
|
+
def Camera::snap(urls, options = {})
|
29
|
+
# create context
|
30
|
+
OSX::NSApplication.sharedApplication
|
31
|
+
|
32
|
+
# create an app delegate
|
33
|
+
delegate = AppDelegate.alloc.init
|
34
|
+
OSX::NSApp.setDelegate(delegate)
|
35
|
+
|
36
|
+
# create a webview object
|
37
|
+
rect = OSX::NSMakeRect(-16000, -16000, 100, 100)
|
38
|
+
webview = OSX::WebView.alloc.initWithFrame(rect)
|
39
|
+
webview.setMediaStyle('screen')
|
40
|
+
webview.mainFrame.frameView.setAllowsScrolling(false)
|
41
|
+
|
42
|
+
# make sure we don't save any of the prefs that we change.
|
43
|
+
webview.preferences.setAutosaves(false)
|
44
|
+
webview.preferences.setShouldPrintBackgrounds(true)
|
45
|
+
webview.preferences.setJavaScriptCanOpenWindowsAutomatically(false)
|
46
|
+
webview.preferences.setAllowsAnimatedImages(false)
|
47
|
+
|
48
|
+
# create a window and set view
|
49
|
+
win = OSX::NSWindow.alloc
|
50
|
+
win.initWithContentRect_styleMask_backing_defer(rect, OSX::NSBorderlessWindowMask, OSX::NSBackingStoreBuffered, false)
|
51
|
+
win.setContentView(webview)
|
52
|
+
|
53
|
+
# create load delegate
|
54
|
+
loader = LoadDelegate.alloc.init
|
55
|
+
loader.urls = urls
|
56
|
+
loader.options = DEFAULT_OPTIONS.merge(options)
|
57
|
+
webview.setFrameLoadDelegate(loader)
|
58
|
+
|
59
|
+
# now run
|
60
|
+
OSX::NSApp.run
|
61
|
+
end
|
62
|
+
|
63
|
+
class AppDelegate < OSX::NSObject
|
64
|
+
def applicationDidFinishLaunching(aNotification)
|
65
|
+
webview = aNotification.object.windows.objectAtIndex(0).contentView
|
66
|
+
webview.frameLoadDelegate.fetchUrl(webview)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class LoadDelegate < OSX::NSObject
|
71
|
+
attr_accessor :options, :urls, :logger
|
72
|
+
|
73
|
+
def urls=(urls)
|
74
|
+
@urls = urls.to_a
|
75
|
+
end
|
76
|
+
|
77
|
+
def options=(options)
|
78
|
+
# adjust configs
|
79
|
+
options[:snapFormatInFilename?] = true if (options[:snapFormat].size > 1) && !options[:snapFormatInFilename?]
|
80
|
+
|
81
|
+
w = options[:clip][:width] / options[:scaleFactor]
|
82
|
+
h = options[:clip][:height] / options[:scaleFactor]
|
83
|
+
options[:browser][:width] = w unless w < options[:browser][:width]
|
84
|
+
options[:browser][:height] = h unless h < options[:browser][:height]
|
85
|
+
|
86
|
+
@options = options
|
87
|
+
end
|
88
|
+
|
89
|
+
def init
|
90
|
+
@logger = Logger.new(STDOUT)
|
91
|
+
self
|
92
|
+
end
|
93
|
+
|
94
|
+
def webView_didFailLoadWithError_forFrame(webview, error, frame)
|
95
|
+
@logger.warn "#{error.localizedDescription}"
|
96
|
+
fetchUrl(webview)
|
97
|
+
end
|
98
|
+
|
99
|
+
def webView_didFailProvisionalLoadWithError_forFrame(webview, error, frame)
|
100
|
+
@logger.warn "#{error.localizedDescription}"
|
101
|
+
fetchUrl(webview)
|
102
|
+
end
|
103
|
+
|
104
|
+
def webView_didFinishLoadForFrame(webview, frame)
|
105
|
+
# don't care about subframes
|
106
|
+
return unless (frame == webview.mainFrame)
|
107
|
+
docview = frame.frameView.documentView
|
108
|
+
resizeWebView(docview)
|
109
|
+
|
110
|
+
@logger.info "Capturing..."
|
111
|
+
url = frame.dataSource.initialRequest.URL.absoluteString
|
112
|
+
bitmap = captureView(docview)
|
113
|
+
saveImages(url, bitmap)
|
114
|
+
|
115
|
+
@logger.info "Done!"
|
116
|
+
fetchUrl(webview)
|
117
|
+
end
|
118
|
+
|
119
|
+
def resetWebView(view)
|
120
|
+
rect = OSX::NSMakeRect(0, 0, browser[:width], browser[:height])
|
121
|
+
view.window.setContentSize([browser[:width], browser[:height]])
|
122
|
+
view.setFrame(rect)
|
123
|
+
end
|
124
|
+
|
125
|
+
def resizeWebView(view)
|
126
|
+
view.setNeedsDisplay(true)
|
127
|
+
view.displayIfNeeded
|
128
|
+
view.window.setContentSize(view.bounds.size)
|
129
|
+
view.setFrame(view.bounds)
|
130
|
+
end
|
131
|
+
|
132
|
+
def captureView(view)
|
133
|
+
view.lockFocus
|
134
|
+
bitmap = OSX::NSBitmapImageRep.alloc
|
135
|
+
bitmap.initWithFocusedViewRect(view.bounds)
|
136
|
+
view.unlockFocus
|
137
|
+
bitmap
|
138
|
+
end
|
139
|
+
|
140
|
+
def fetchUrl(webview)
|
141
|
+
OSX::NSApplication.sharedApplication.terminate(self) if @urls.empty?
|
142
|
+
|
143
|
+
url = String.new(@urls.shift)
|
144
|
+
|
145
|
+
url.gsub!(/^/, "http:\/\/") unless url =~ /^(http(s)?|file):\/\//
|
146
|
+
@logger.info "Fetching #{url}..."
|
147
|
+
|
148
|
+
resetWebView(webview)
|
149
|
+
webview.mainFrame.loadRequest(OSX::NSURLRequest.requestWithURL(OSX::NSURL.URLWithString(url)))
|
150
|
+
|
151
|
+
return if webview.mainFrame.provisionalDataSource
|
152
|
+
fetchUrl(webview)
|
153
|
+
end
|
154
|
+
|
155
|
+
def makeFilename(url, bitmap, format)
|
156
|
+
if !filename.empty?
|
157
|
+
name = filename
|
158
|
+
|
159
|
+
elsif useHashForFilename?
|
160
|
+
name = Digest::MD5.new.hexdigest(url)
|
161
|
+
|
162
|
+
else
|
163
|
+
name = String.new(url)
|
164
|
+
name.gsub!(/\W/, '');
|
165
|
+
name.gsub!(/^http(s)?/i, '');
|
166
|
+
name.gsub!(/\//, '.');
|
167
|
+
end
|
168
|
+
|
169
|
+
name = "#{Time.now.strftime('%H%M%S')}-#{name}" if timestampInFilename?
|
170
|
+
name = "#{Time.now.strftime('%Y%m%d')}-#{name}" if datestampInFilename?
|
171
|
+
name = "#{name}-#{bitmap.pixelsWide}x#{bitmap.pixelsHigh}" if sizeInFilename?
|
172
|
+
name = "#{name}-#{format}" if snapFormatInFilename?
|
173
|
+
|
174
|
+
name = "#{name}.png"
|
175
|
+
|
176
|
+
name = File.join(File.expand_path(outputDirectory), name) unless outputDirectory.empty?
|
177
|
+
name
|
178
|
+
end
|
179
|
+
|
180
|
+
def saveImages(url, bitmap)
|
181
|
+
writeToFile(url, bitmap, :fullsize) if snapFormat.include?(:fullsize)
|
182
|
+
|
183
|
+
if snapFormat.include?(:thumbnail) || snapFormat.include?(:clip)
|
184
|
+
# work out how big the thumbnail is
|
185
|
+
thumbWidth = bitmap.pixelsWide * scaleFactor
|
186
|
+
thumbHeight = bitmap.pixelsHigh * scaleFactor
|
187
|
+
|
188
|
+
# make the thumbnails in a scratch image
|
189
|
+
scratch = OSX::NSImage.alloc.initWithSize(OSX::NSMakeSize(thumbWidth, thumbHeight))
|
190
|
+
scratch.lockFocus
|
191
|
+
OSX::NSGraphicsContext.currentContext.setImageInterpolation(OSX::NSImageInterpolationHigh)
|
192
|
+
thumbRect = OSX::NSMakeRect(0.0, 0.0, thumbWidth, thumbHeight)
|
193
|
+
clipRect = OSX::NSMakeRect(0.0, thumbHeight - clip[:height], clip[:width], clip[:height])
|
194
|
+
bitmap.drawInRect(thumbRect)
|
195
|
+
thumbnail = OSX::NSBitmapImageRep.alloc.initWithFocusedViewRect(thumbRect)
|
196
|
+
clipping = OSX::NSBitmapImageRep.alloc.initWithFocusedViewRect(clipRect)
|
197
|
+
scratch.unlockFocus
|
198
|
+
|
199
|
+
# save the thumbnails as pngs
|
200
|
+
writeToFile(url, thumbnail, :thumbnail) if snapFormat.include?(:thumbnail)
|
201
|
+
writeToFile(url, clipping, :clip) if snapFormat.include?(:clip)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
def writeToFile(url, bitmap, format)
|
206
|
+
name = makeFilename(url, bitmap, format)
|
207
|
+
FileUtils.mkdir_p File.dirname(name)
|
208
|
+
bitmap.representationUsingType_properties(OSX::NSPNGFileType, nil).writeToFile_atomically(name, true)
|
209
|
+
end
|
210
|
+
|
211
|
+
def ping(url)
|
212
|
+
open(url) rescue nil
|
213
|
+
end
|
214
|
+
|
215
|
+
def method_missing(name, *args)
|
216
|
+
if args.empty?
|
217
|
+
k = name.to_sym
|
218
|
+
super(name, args) unless @options.keys.include?(k)
|
219
|
+
return @options[k]
|
220
|
+
end
|
221
|
+
super(name, args)
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
225
|
+
end
|
data/lib/snapurl.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
=begin
|
2
|
+
* Name: SnapUrl
|
3
|
+
* Description:
|
4
|
+
* This is a Ruby/RubyCocoa port of the webkit2png.py script by Paul Hammond
|
5
|
+
* (http://www.paulhammond.org/webkit2png/) with some minor modifications.
|
6
|
+
* Author: Juris Galang (http://www.JurisGalang.com)
|
7
|
+
* Date: 09/15/08
|
8
|
+
* License:
|
9
|
+
=end
|
10
|
+
require 'digest/md5'
|
11
|
+
require 'fileutils'
|
12
|
+
require 'logger'
|
13
|
+
require 'optparse'
|
14
|
+
require 'ostruct'
|
15
|
+
require 'open-uri'
|
16
|
+
|
17
|
+
require 'osx/cocoa'
|
18
|
+
OSX.require_framework 'WebKit'
|
19
|
+
|
20
|
+
require 'core/camera'
|
21
|
+
require 'core/application'
|
22
|
+
|
23
|
+
Version = "0.0.3"
|
24
|
+
Release = "alpha"
|
25
|
+
|
26
|
+
module SnapUrl
|
27
|
+
VERSION = Version
|
28
|
+
end
|
File without changes
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mocoso-snapurl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: universal-darwin
|
6
|
+
authors:
|
7
|
+
- Juris Galang
|
8
|
+
- Joel Chippindale
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2009-10-19 00:00:00 +01:00
|
14
|
+
default_executable: snapurl
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: This is a Ruby/RubyCocoa port of the webkit2png.py script by Paul Hammond* (http://www.paulhammond.org/webkit2png/) with some minor modifications.
|
18
|
+
email: joel.chippindale@gmail.com
|
19
|
+
executables:
|
20
|
+
- snapurl
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- .gitignore
|
27
|
+
- History.txt
|
28
|
+
- MIT-LICENSE
|
29
|
+
- Manifest.txt
|
30
|
+
- README.rdoc
|
31
|
+
- Rakefile
|
32
|
+
- VERSION.yml
|
33
|
+
- bin/snapurl
|
34
|
+
- lib/core/application.rb
|
35
|
+
- lib/core/camera.rb
|
36
|
+
- lib/snapurl.rb
|
37
|
+
- test/test_snapurl.rb
|
38
|
+
- thirdparty/RubyCocoa-0.13.2.tgz
|
39
|
+
has_rdoc: true
|
40
|
+
homepage:
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options:
|
45
|
+
- --charset=UTF-8
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: "0"
|
53
|
+
version:
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: "0"
|
59
|
+
version:
|
60
|
+
requirements:
|
61
|
+
- Mac OS X 10.5 or later
|
62
|
+
- RubyCocoa
|
63
|
+
rubyforge_project:
|
64
|
+
rubygems_version: 1.3.5
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Render HTML to PNG using WebKit
|
68
|
+
test_files:
|
69
|
+
- test/test_snapurl.rb
|