retina_rails
retina_rails copied to clipboard
prevent @2x generation
When a new image is uploaded (Paperclip in my case). How can I prevent a @2x version to be generated when the image is too small, and having the @2x version would only abuse the bandwidth without any increase in quality?
Hi @Janther,
If I understand correctly you don't want to generate an at2x version for certain styles eg. small. We currently don't support that feature yet. I think it would be nice to have an option to do:
has_attached_file :image,
:styles => {
:original => ["800x800", :jpg],
:large => ["125x125#", :jpg],
:medium => ["80x80#", :jpg],
:small => ["25x25#", :jpg
},
:retina => [:large, :medium]
Let me know what you think.
I like that @jhnvz !
Sorry @jhnvz, I explained poorly.
Considering these styles:
has_attached_file :image,
:styles => {
:large => "250x250#",
:thumb => "50x50#"
},
:retina => true
The large style would be 250x250 and the @2x 500x500 (am I right?).
But what if my user uploads an image with a size of 230x230? I don't mind the upscale to 250x250 but the @2x would be too much and won't do any quality improvement. Making the retina capable browser download the large image AND the @2x one with a decent quality for 250x250 but definitely not a good one for the @2x.
I just thought about trying a lambda in the retina statement, but don't know if it will work.
PS: I also like the :retina => [:large, :medium]
Interesting idea. It makes sense not to process images that aren't bigger than the version size. I think setting this up as default behavior is definitely a nice performance boost. We would have to hook in after the upload and get the dimensions. What do you think @jhnvz?
Version 2 (#39) makes this behavior obsolete
I'm still seeing this as a potential issue. I just upgraded to 2.0 and found that this issue can still persist if the original image dimensions are less than the 2x dimensions and the quality is getting lowered. Its not a huge, deal. But I can definitely see the difference in image quality.
So for example. My original image is 600px
and style is set at :large => "400x400#"
and my retina quality is set at 75. Giving me an 800px
image with 75% of the original quality + whatever quality got lost in the extra 200px
stretch.
So I think it would still be beneficial to skip the retina resizing if the original dimensions are less than the largest style * 2.
I did some tests and can see the difference on non retina displays. But this may be beyond the scope of where you want to take the gem.
I would love to hear your thoughts.
Hi @Waylon87. You are totally right. I'll try to come up with a fix by the end of this or next week. The idea of the gem is "better image quality on retina displays" not "possible degraded quality on retina- and non-retina displays". Thanks for the detailed use case!
@jhnvz Thanks! Looking forward to it!