color_cat 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/color_cat/process.rb +16 -4
- data/lib/color_cat/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3a7dab54fe1ad551c0adf7bd00cdee307abb93d9
|
4
|
+
data.tar.gz: 0f17ba4c6d897fc5a4b52b767701c7e3cef48f9c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f069ef0a0ed025683e23f2f98895db05e772e7348ef83ad5a41fa7bcfc7bae7b8d6c0c4c42d4e302383585e4b7a3a8ce9df87013044c04a9186c68d5ec919bfb
|
7
|
+
data.tar.gz: 66534b7b33b94f0384683a8c89ea36ed05cdc9ba5e1db900ae03b9a43ae0ee1fc762857087fdfbe5c42a1e6ef117a7784c58af35137c3a9ce9e852c5574fcd71
|
data/lib/color_cat/process.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'RMagick'
|
2
|
+
require "open-uri"
|
2
3
|
|
3
4
|
module ColorCat
|
4
5
|
class Process
|
@@ -13,9 +14,12 @@ module ColorCat
|
|
13
14
|
end
|
14
15
|
|
15
16
|
def call
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
begin
|
18
|
+
process_image
|
19
|
+
normal = sort_by_decreasing_frequency(quantized)
|
20
|
+
get_pix(normal)
|
21
|
+
rescue OpenURI::HTTPError
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
def self.call(url, opts={})
|
@@ -74,7 +78,7 @@ module ColorCat
|
|
74
78
|
private
|
75
79
|
|
76
80
|
def process_image
|
77
|
-
@original = Magick::Image.read(url).first
|
81
|
+
@original = Magick::Image.read(save_to_tempfile(url).path).first
|
78
82
|
@quantized = original.quantize(NUMBER_OF_COLORS, Magick::RGBColorspace)
|
79
83
|
end
|
80
84
|
|
@@ -113,5 +117,13 @@ module ColorCat
|
|
113
117
|
self
|
114
118
|
end
|
115
119
|
|
120
|
+
def save_to_tempfile(url_or_path)
|
121
|
+
tempfile = Tempfile.new("testfile.jpg")
|
122
|
+
tempfile.binmode
|
123
|
+
tempfile << open(url_or_path).read
|
124
|
+
tempfile.rewind
|
125
|
+
tempfile
|
126
|
+
end
|
127
|
+
|
116
128
|
end
|
117
129
|
end
|
data/lib/color_cat/version.rb
CHANGED