|
@@ -69,20 +69,20 @@ end
|
|
|
|
|
|
require 'mini_magick'
|
|
require 'mini_magick'
|
|
|
|
|
|
-def convert_image(source, target, width: nil, round: false)
|
|
|
|
|
|
+def convert_image(source, target, options = {}) # width: nil, round: false
|
|
ext = target[/(?<=\.)[^.]+\z/] || 'png'
|
|
ext = target[/(?<=\.)[^.]+\z/] || 'png'
|
|
original = MiniMagick::Image.open(source)
|
|
original = MiniMagick::Image.open(source)
|
|
|
|
|
|
result = original
|
|
result = original
|
|
result.format ext
|
|
result.format ext
|
|
|
|
|
|
- if width
|
|
|
|
|
|
+ if width = options[:width]
|
|
result.thumbnail '%1$dx%1$d>' % width
|
|
result.thumbnail '%1$dx%1$d>' % width
|
|
else
|
|
else
|
|
width = result[:width]
|
|
width = result[:width]
|
|
end
|
|
end
|
|
|
|
|
|
- if round
|
|
|
|
|
|
+ if options[:round]
|
|
radius = (Rational(80, 512) * width).round
|
|
radius = (Rational(80, 512) * width).round
|
|
|
|
|
|
mask = MiniMagick::Image.create(ext) { |tmp| result.write(tmp) }
|
|
mask = MiniMagick::Image.create(ext) { |tmp| result.write(tmp) }
|