insano_image_resizer 0.3.6 → 0.3.7
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.
- data/lib/insano_image_resizer/processor.rb +10 -6
- metadata +1 -1
@@ -8,6 +8,10 @@ module InsanoImageResizer
|
|
8
8
|
include Shell
|
9
9
|
include Loggable
|
10
10
|
|
11
|
+
def initialize(options = {vips_path: "vips"})
|
12
|
+
@vips_path = options[:vips_path]
|
13
|
+
end
|
14
|
+
|
11
15
|
def process(input_path, viewport_size = {}, interest_point = {}, quality = 60)
|
12
16
|
input_properties = fetch_image_properties(input_path)
|
13
17
|
input_has_alpha = (input_properties[:bands] == 4)
|
@@ -25,9 +29,9 @@ module InsanoImageResizer
|
|
25
29
|
# There's actually some extra metadata we ignore here, but this seems to be
|
26
30
|
# the only way to get width and height from VIPS.
|
27
31
|
result = {}
|
28
|
-
result[:w] = run("
|
29
|
-
result[:h] = run("
|
30
|
-
result[:bands] = run("
|
32
|
+
result[:w] = run("#{@vips_path} im_header_int Xsize '#{input_path}'").to_f
|
33
|
+
result[:h] = run("#{@vips_path} im_header_int Ysize '#{input_path}'").to_f
|
34
|
+
result[:bands] = run("#{@vips_path} im_header_int Bands '#{input_path}'").to_f
|
31
35
|
return result
|
32
36
|
end
|
33
37
|
|
@@ -197,12 +201,12 @@ module InsanoImageResizer
|
|
197
201
|
end
|
198
202
|
intermediate_path = input_path[0..-4]+"_shrunk." + output_extension
|
199
203
|
|
200
|
-
run("
|
201
|
-
run("
|
204
|
+
run("#{@vips_path} im_shrink '#{input_path}' '#{intermediate_path}#{quality_extension}' #{shrink_factor} #{shrink_factor}")
|
205
|
+
run("#{@vips_path} im_affine '#{intermediate_path}' '#{output_path}#{quality_extension}' #{transform[:scale]} 0 0 #{transform[:scale]} 0 0 #{transform[:x]} #{transform[:y]} #{transform[:w]} #{transform[:h]}")
|
202
206
|
FileUtils.rm(intermediate_path)
|
203
207
|
|
204
208
|
else
|
205
|
-
run("
|
209
|
+
run("#{@vips_path} im_affine '#{input_path}' '#{output_path}#{quality_extension}' #{transform[:scale]} 0 0 #{transform[:scale]} 0 0 #{transform[:x]} #{transform[:y]} #{transform[:w]} #{transform[:h]}")
|
206
210
|
|
207
211
|
end
|
208
212
|
|