Custom processors?
Closed this issue · 3 comments
glebm commented
In order to avoid having to call manipulate!
multiple times during processing (which essentialy calls imagemagick), which greatly increases processing time and decreases quality due to multiple jpeg compressor passes, I wrote a custom filter which includes resizing.
How can I make retina_rails
work with this?
For example:
# process resize_to_fill_with_gravity: [100, 100, 'North', :jpg, 75]
def resize_to_fill_with_gravity(width, height, gravity, format, quality)
manipulate! do |img|
cols, rows = img[:dimensions]
img.format(format.to_s.downcase) do |i|
if width != cols || height != rows
scale = [width/cols.to_f, height/rows.to_f].max
cols, rows = (scale * (cols + 0.5)).round, (scale * (rows + 0.5)).round
i.resize "#{cols}x#{rows}"
end
i.gravity gravity
i.background "rgba(255,255,255,0.0)"
i.extent "#{width}x#{height}" if cols != width || rows != height
i.quality quality.to_s
end
img = yield(img) if block_given?
img
end
file.content_type = 'image/jpeg' if format.to_s =~ /jpe?g/ # must set explicitly
end
jhnvz commented
Tricky one. Since you're passing your own arguments to the processor there's no way for retina_rails to detect the width and height.
Arjeno commented
jhnvz commented
You can also do:
version :small do
process resize_to_fill_with_gravity: [100, 100, 'North', :jpg, 75]
end
version :small_retina do
process resize_to_fill_with_gravity: [200, 200, 'North', :jpg, 40]
end
We should mention it in the docs. I will close this issue after i write a spec.