wraith 1.1.6 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -3
- data/configs/config.yaml +1 -1
- data/configs/config_nojs.yaml +1 -1
- data/configs/test_config.yaml +1 -1
- data/lib/wraith/compare_images.rb +2 -2
- data/lib/wraith/crop.rb +17 -28
- data/lib/wraith/save_images.rb +35 -6
- data/lib/wraith/thumbnails.rb +6 -2
- data/lib/wraith/version.rb +1 -1
- data/lib/wraith/wraith.rb +6 -0
- data/wraith.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad34e154a31f1f604bd6254c51272dc90f99b54e
|
4
|
+
data.tar.gz: d981692a40143a35cf38a5dfb688ff2302085661
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9e219db7678d8e51d2c3190d48a9105b88e0326ebc6a90a208a046b6f7ebc5da76164ed72b53f8b9eefcfc61e6548875052f17d060b280268f60998962ad0f5
|
7
|
+
data.tar.gz: ca393aff8ab9c00a5887b1b786c4a5a1a95fab4d1fe17dad89305dedcd50c50efc8e98edb77fc11cf8946a9c344b76f25fbd4737ce828296413b815766d47da6
|
data/README.md
CHANGED
@@ -22,7 +22,7 @@ diff](http://bbc-news.github.io/wraith/img/320_diff.png)
|
|
22
22
|
|
23
23
|
## Requirements
|
24
24
|
|
25
|
-
To read our detailed instructions for setup and install, as well as example configs, visit [wraith docs](http://bbc-news.github.io/wraith/index.html)
|
25
|
+
Imagemagick and PhantomJS are required to use Wraith, install via your favourite package manager. To read our detailed instructions for setup and install, as well as example configs, visit [wraith docs](http://bbc-news.github.io/wraith/index.html)
|
26
26
|
|
27
27
|
## Installation
|
28
28
|
|
@@ -83,8 +83,8 @@ If you want to add functionality to this project, pull requests are welcome.
|
|
83
83
|
|
84
84
|
**Please raise any issues with this project as a GitHub issue.**
|
85
85
|
|
86
|
-
## Changelog - updated 2014-
|
87
|
-
We have
|
86
|
+
## Changelog - updated 2014-05-14
|
87
|
+
We have updated Wraith some bug fixes and more importantly, parallel support. This will now enable use of all your CPU cores for faster Wraith runs. There is error handling in place to ensure if an image fails to capture, it will try again 5 times, if that fails, it will put an holding image in place. This should solve all the issues with images not capturing and failing to crop/compare. Big thanks to [Matt Senior](https://github.com/mattsenior) for doing the work.
|
88
88
|
|
89
89
|
## License
|
90
90
|
|
data/configs/config.yaml
CHANGED
data/configs/config_nojs.yaml
CHANGED
data/configs/test_config.yaml
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'wraith'
|
2
2
|
require 'image_size'
|
3
3
|
require 'open3'
|
4
|
+
require 'parallel'
|
4
5
|
|
5
6
|
class Wraith::CompareImages
|
6
7
|
attr_reader :wraith
|
@@ -11,8 +12,7 @@ class Wraith::CompareImages
|
|
11
12
|
|
12
13
|
def compare_images
|
13
14
|
files = Dir.glob("#{wraith.directory}/*/*.png").sort
|
14
|
-
|
15
|
-
base, compare = files.slice!(0, 2)
|
15
|
+
Parallel.each(files.each_slice(2), :in_processes => Parallel.processor_count) do |base, compare|
|
16
16
|
diff = base.gsub(/([a-z0-9]+).png$/, 'diff.png')
|
17
17
|
info = base.gsub(/([a-z0-9]+).png$/, 'data.txt')
|
18
18
|
compare_task(base, compare, diff, info)
|
data/lib/wraith/crop.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'wraith'
|
2
2
|
require 'image_size'
|
3
|
+
require 'parallel'
|
3
4
|
|
4
5
|
class Wraith::CropImages
|
5
6
|
attr_reader :wraith
|
@@ -8,41 +9,29 @@ class Wraith::CropImages
|
|
8
9
|
@wraith = Wraith::Wraith.new(config)
|
9
10
|
end
|
10
11
|
|
11
|
-
def crop
|
12
|
-
crop_value(base_height, compare_height, @compare, @base)
|
13
|
-
end
|
14
|
-
|
15
|
-
def height
|
16
|
-
crop_value(base_height, compare_height, base_height, compare_height)
|
17
|
-
end
|
18
|
-
|
19
|
-
def base_height
|
20
|
-
find_heights(@base)
|
21
|
-
end
|
22
|
-
|
23
|
-
def compare_height
|
24
|
-
find_heights(@compare)
|
25
|
-
end
|
26
|
-
|
27
12
|
def crop_images
|
28
13
|
files = Dir.glob("#{wraith.directory}/*/*.png").sort
|
29
|
-
|
30
|
-
|
14
|
+
|
15
|
+
Parallel.each(files.each_slice(2), :in_processes => Parallel.processor_count) do |base, compare|
|
31
16
|
puts 'cropping images'
|
32
|
-
Wraith::Wraith.crop_images(crop, height)
|
33
|
-
end
|
34
|
-
end
|
35
17
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
18
|
+
base_height = image_height(base)
|
19
|
+
compare_height = image_height(compare)
|
20
|
+
|
21
|
+
if base_height > compare_height
|
22
|
+
image_to_crop = compare
|
23
|
+
height_to_crop_to = base_height
|
24
|
+
else
|
25
|
+
image_to_crop = base
|
26
|
+
height_to_crop_to = compare_height
|
27
|
+
end
|
28
|
+
|
29
|
+
Wraith::Wraith.crop_images(image_to_crop, height_to_crop_to)
|
41
30
|
end
|
42
31
|
end
|
43
32
|
|
44
|
-
def
|
45
|
-
File.open(
|
33
|
+
def image_height(image)
|
34
|
+
File.open(image, 'rb') do |fh|
|
46
35
|
size = ImageSize.new(fh.read).size
|
47
36
|
height = size[1]
|
48
37
|
end
|
data/lib/wraith/save_images.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'wraith'
|
2
|
+
require 'parallel'
|
2
3
|
|
3
4
|
class Wraith::SaveImages
|
4
5
|
attr_reader :wraith
|
@@ -36,22 +37,50 @@ class Wraith::SaveImages
|
|
36
37
|
"#{directory}/#{label}/#{width}_#{engine}_#{domain_label}.png"
|
37
38
|
end
|
38
39
|
|
40
|
+
def attempt_image_capture(width, url, filename, max_attempts)
|
41
|
+
max_attempts.times do |i|
|
42
|
+
wraith.capture_page_image engine, url, width, filename
|
43
|
+
|
44
|
+
return if File.exist? filename
|
45
|
+
|
46
|
+
puts "Failed to capture image #{filename} on attempt number #{i+1} of #{max_attempts}"
|
47
|
+
end
|
48
|
+
|
49
|
+
raise "Unable to capture image #{filename} after #{max_attempts} attempt(s)"
|
50
|
+
end
|
51
|
+
|
39
52
|
def save_images
|
53
|
+
jobs = []
|
40
54
|
check_paths.each do |label, path|
|
41
55
|
if !path
|
42
|
-
path = label
|
43
|
-
label = path.gsub('/', '_')
|
56
|
+
path = label
|
57
|
+
label = path.gsub('/', '_')
|
44
58
|
end
|
45
59
|
|
46
60
|
base_url = base_urls(path)
|
47
61
|
compare_url = compare_urls(path)
|
48
62
|
|
49
63
|
wraith.widths.each do |width|
|
50
|
-
base_file_name
|
64
|
+
base_file_name = file_names(width, label, wraith.base_domain_label)
|
51
65
|
compare_file_name = file_names(width, label, wraith.comp_domain_label)
|
52
|
-
|
53
|
-
|
54
|
-
|
66
|
+
|
67
|
+
jobs << [label, path, width, base_url, base_file_name]
|
68
|
+
jobs << [label, path, width, compare_url, compare_file_name]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
Parallel.each(jobs, :in_threads => 8) do |label, path, width, url, filename|
|
73
|
+
begin
|
74
|
+
attempt_image_capture(width, url, filename, 5)
|
75
|
+
rescue Exception => e
|
76
|
+
puts e
|
77
|
+
|
78
|
+
puts "Using fallback image instead"
|
79
|
+
invalid = File.expand_path('../../assets/invalid.jpg', File.dirname(__FILE__))
|
80
|
+
FileUtils.cp invalid, filename
|
81
|
+
|
82
|
+
# Set width of fallback image
|
83
|
+
wraith.set_image_width(filename, width)
|
55
84
|
end
|
56
85
|
end
|
57
86
|
end
|
data/lib/wraith/thumbnails.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'wraith'
|
2
|
+
require 'parallel'
|
2
3
|
|
3
4
|
class Wraith::Thumbnails
|
4
5
|
attr_reader :wraith
|
@@ -8,10 +9,13 @@ class Wraith::Thumbnails
|
|
8
9
|
end
|
9
10
|
|
10
11
|
def generate_thumbnails
|
11
|
-
|
12
|
+
puts 'Generating thumbnails'
|
13
|
+
|
14
|
+
files = Dir.glob("#{wraith.directory}/*/*.png")
|
15
|
+
|
16
|
+
Parallel.each(files, :in_processes => Parallel.processor_count) do |filename|
|
12
17
|
new_name = filename.gsub(/^#{wraith.directory}/, "#{wraith.directory}/thumbnails")
|
13
18
|
wraith.thumbnail_image(filename, new_name)
|
14
19
|
end
|
15
|
-
puts 'Generating thumbnails'
|
16
20
|
end
|
17
21
|
end
|
data/lib/wraith/version.rb
CHANGED
data/lib/wraith/wraith.rb
CHANGED
@@ -73,6 +73,12 @@ class Wraith::Wraith
|
|
73
73
|
self.class.crop_images
|
74
74
|
end
|
75
75
|
|
76
|
+
def set_image_width(image, width)
|
77
|
+
# For compatibility with windows file structures switch commenting on the following 2 lines
|
78
|
+
puts `convert #{image} -background none -extent #{width}x0 #{image}`
|
79
|
+
# puts `convert #{image.gsub('/', '\\')} -background none -extent #{width}x0 #{image.gsub('/', '\\')}`
|
80
|
+
end
|
81
|
+
|
76
82
|
def thumbnail_image(png_path, output_path)
|
77
83
|
# For compatibility with windows file structures switch commenting on the following 2 lines
|
78
84
|
`convert #{png_path} -thumbnail 200 -crop 200x200+0+0 #{output_path}`
|
data/wraith.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wraith
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dave Blooman
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-05-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: pry
|
@@ -137,6 +137,20 @@ dependencies:
|
|
137
137
|
- - '>='
|
138
138
|
- !ruby/object:Gem::Version
|
139
139
|
version: '0'
|
140
|
+
- !ruby/object:Gem::Dependency
|
141
|
+
name: parallel
|
142
|
+
requirement: !ruby/object:Gem::Requirement
|
143
|
+
requirements:
|
144
|
+
- - '>='
|
145
|
+
- !ruby/object:Gem::Version
|
146
|
+
version: '0'
|
147
|
+
type: :runtime
|
148
|
+
prerelease: false
|
149
|
+
version_requirements: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
140
154
|
description: Wraith is a screenshot comparison tool, created by developers at BBC
|
141
155
|
News.
|
142
156
|
email:
|