Automatically generate images with @2x.extension?

81 views
Skip to first unread message

Ketan Anjaria

unread,
Apr 17, 2013, 11:43:22 PM4/17/13
to dragonf...@googlegroups.com
I'm looking for a way to serve responsive images with "@2x" appended to the file name.
Is there a way in dragonfly if I make a request for an image url, it automatically creates the a doubled size version?
For example if i request user.avatar.thumb("100x100#").encode(:jpg, '-quality 80').url it also creates a 
200x200 image with the same name but @2x before the the jpg extension?

Mark Evans

unread,
Apr 19, 2013, 2:10:52 PM4/19/13
to dragonf...@googlegroups.com
hi

this should work (if I've understood your question correctly):

    user.avatar.thumb("200x200#").encode(:jpg, '-quality 80').url(:basename => "#{user.avatar.basename}@2x")

also see http://markevans.github.io/dragonfly/file.URLs.html#Path_format for other things you can do with the path format

In the future I'm adding the ability for a processor step to automatically update the url, but for now it's easier to pass extra options to the call to "url" (these options correspond to tokens in the "url_format" string)

--
You received this message because you are subscribed to the Google Groups "Dragonfly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dragonfly-use...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Jarin Udom

unread,
Aug 17, 2013, 9:13:24 PM8/17/13
to dragonf...@googlegroups.com
Hi, thanks for the great work :)

It would be super handy if there's a way for Dragonfly to automatically recognize the @2x at the end of the URL and double the dimensions, since there are javascript tools like retina.js out there. Basically, retina.js looks for images on the page if the device supports retina resolution and attempts to replace them with a @2x version after the page finishes loading.

Best regards,
Jarin

Mark Evans

unread,
Aug 19, 2013, 6:39:32 PM8/19/13
to dragonf...@googlegroups.com
I think the easiest way to do that would be to use custom endpoints http://markevans.github.io/dragonfly/file.URLs.html#Routed_Endpoints
Otherwise it's a bit too specific a use case to include in dragonfly by default I think

Dmitriy Likhten

unread,
Aug 20, 2013, 7:47:45 AM8/20/13
to dragonf...@googlegroups.com

Funny. We solved this issue by serving svg versions of our images with a png fallback. Only ie 8 needs the fallback

On Aug 19, 2013 6:39 PM, "Mark Evans" <mark.jo...@gmail.com> wrote:
I think the easiest way to do that would be to use custom endpoints http://markevans.github.io/dragonfly/file.URLs.html#Routed_Endpoints
Otherwise it's a bit too specific a use case to include in dragonfly by default I think

Reply all
Reply to author
Forward
0 new messages