phantoshot 0.0.1 → 0.0.2
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 +8 -8
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/lib/phantom-shot-script.js +2 -8
- data/lib/phantoshot/make_screenshot.rb +36 -7
- data/lib/phantoshot/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmI1ZjRkNjA0MDI4ZTllZmEzMGU4MmNmMDQwYzE0Y2Y2YWI0N2MyMg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
Y2I5MzhiZjUxMjJkYTBmYzI5OTZiYjY1YjA4NmUxMjQxODE3OGMxNg==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NTEyZjQwNmVmOWIyMGJlOTkyY2MwOGVlNDJlN2RmNGUwZjU1YWQ5MjQwNGEw
|
10
|
+
NzM4MjE0ZjJmZTcxMTdjYjRjN2RkZmZhMWI1YzQ5OTA4NGEzYzEyMjUxNmU2
|
11
|
+
NzI0MjExOWU0ODkxM2ZkNmE5NmY4ZDIzODc1Y2EzMjVlZDdiNDU=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
MGEwNWFmMDQ5MjBmNGM4OTE0Y2I2YTQ3NzIyMWExYjQxMTljZWZiNzdjYzg2
|
14
|
+
NWIxZDQyOTA4NDBmYjk0OTY2ZTUxM2JiYWQ2N2IyZDkzOWM3Y2I4ZDcxODk4
|
15
|
+
YjFmYWIwZjExNGY4MWFjMjk1NTUyNDdlODdiYTRjYTQxNGQxZTI=
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -24,6 +24,7 @@ GEM
|
|
24
24
|
method_source (~> 0.8)
|
25
25
|
slop (~> 3.4)
|
26
26
|
rake (10.0.4)
|
27
|
+
rmagick (2.13.2)
|
27
28
|
rspec (2.13.0)
|
28
29
|
rspec-core (~> 2.13.0)
|
29
30
|
rspec-expectations (~> 2.13.0)
|
@@ -46,4 +47,5 @@ DEPENDENCIES
|
|
46
47
|
phantoshot!
|
47
48
|
pry
|
48
49
|
rake
|
50
|
+
rmagick
|
49
51
|
rspec (~> 2.8)
|
data/lib/phantom-shot-script.js
CHANGED
@@ -3,22 +3,16 @@ var system = require('system');
|
|
3
3
|
|
4
4
|
var result = {
|
5
5
|
url: system.args[1],
|
6
|
-
width: parseInt(system.args[2]),
|
7
|
-
height: parseInt(system.args[3])
|
8
6
|
};
|
9
7
|
|
10
8
|
|
11
|
-
page.viewportSize = {
|
12
|
-
width: result.width,
|
13
|
-
height: result.height
|
14
|
-
};
|
15
|
-
|
16
9
|
page.open(result.url, function() {
|
17
10
|
|
18
11
|
result.file_format = 'PNG';
|
19
12
|
result.image_data = page.renderBase64(result.file_format);
|
20
13
|
|
21
|
-
console.log( JSON.stringify(result) );
|
22
14
|
|
15
|
+
|
16
|
+
console.log( JSON.stringify(result) );
|
23
17
|
phantom.exit();
|
24
18
|
});
|
@@ -1,24 +1,53 @@
|
|
1
1
|
module Phantoshot
|
2
|
+
require 'rmagick'
|
3
|
+
include Magick
|
4
|
+
|
2
5
|
def make_screenshot(url, opts={})
|
3
6
|
|
4
|
-
|
5
|
-
|
7
|
+
desired_width = opts[:width]
|
8
|
+
desired_height = opts[:height]
|
6
9
|
|
7
|
-
res = MultiJson.load(
|
10
|
+
res = MultiJson.load(
|
11
|
+
phantom_command(url)
|
12
|
+
)
|
8
13
|
|
9
14
|
hsh = Hashie::Mash.new(res)
|
10
15
|
|
11
16
|
# Decode it for writing out to binary
|
12
|
-
hsh[:image_data] = Base64.decode64( hsh[:image_data] )
|
17
|
+
hsh[:image_data] = Base64.decode64( hsh[:image_data] )
|
18
|
+
|
19
|
+
tempfile = Tempfile.new('foo.png')
|
20
|
+
tempfile.write(hsh[:image_data])
|
21
|
+
tempfile.close
|
22
|
+
|
23
|
+
img = Image.read(tempfile.path)[0]
|
24
|
+
org_width = img.columns
|
25
|
+
org_height = img.rows
|
26
|
+
|
27
|
+
if desired_width
|
28
|
+
img = img.resize_to_fit(desired_width, org_height)
|
29
|
+
end
|
30
|
+
|
31
|
+
if desired_height
|
32
|
+
img = img.crop(0, 0, img.columns, desired_height)
|
33
|
+
end
|
34
|
+
|
35
|
+
tempfile2 = Tempfile.new('bar.png')
|
36
|
+
|
37
|
+
img.write(tempfile2.path)
|
38
|
+
|
39
|
+
tempfile2.close
|
40
|
+
|
41
|
+
hsh[:image_data] = open(tempfile2.path){ |f| f.read }
|
13
42
|
return hsh
|
14
43
|
end
|
15
44
|
|
16
45
|
|
17
46
|
# returns JSON string with these attributes:
|
18
|
-
# :image_data (in base64), :
|
47
|
+
# :image_data (in base64), :file_format (default is PNG), and :url
|
19
48
|
#
|
20
|
-
def phantom_command(url
|
21
|
-
cmd = "phantomjs #{JS_LIB_NAME} #{url}
|
49
|
+
def phantom_command(url)
|
50
|
+
cmd = "phantomjs #{JS_LIB_NAME} #{url}"
|
22
51
|
`#{cmd}`
|
23
52
|
end
|
24
53
|
end
|
data/lib/phantoshot/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: phantoshot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Callahan
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-06-
|
12
|
+
date: 2013-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|