Is there any tool available for image upload resizing / view based image style rendering?

36 views
Skip to first unread message

Waseem Massry

unread,
May 16, 2016, 4:54:14 AM5/16/16
to rubyonra...@googlegroups.com
What is the best method to manage image uploads in Rails? Is there a
tool that allows auto-resizing upon image upload based on predefined
dimensions? Moreover, is there any tool available that makes it possible
to render / regenerate the same originally uploaded image using
alternative view based styles, e.g. thumbs, 320x200 or 640x480 etc..?
Thanks.

--
Posted via http://www.ruby-forum.com/.

Johnny Stewart

unread,
May 16, 2016, 7:51:52 AM5/16/16
to rubyonra...@googlegroups.com
Hi there,

I'd take a look at attache:

https://github.com/choonkeat/attache-rails

https://github.com/choonkeat/attache

regards,

Johnny

Walter Lee Davis

unread,
May 16, 2016, 11:48:36 AM5/16/16
to rubyonra...@googlegroups.com
Also look at dragonfly. It does "lazy" resizing, so you upload once, then set the size you want later in the view. Images resized in this manner are cached so you only pay the ImageMagick tax once.

Walter
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e56d8e62b79ee1620848fb9fb6f460fd%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

W. M.

unread,
May 17, 2016, 8:05:18 AM5/17/16
to rubyonra...@googlegroups.com
Walter Davis wrote in post #1183498:
> Also look at dragonfly. It does "lazy" resizing, so you upload once,
> then set the size you want later in the view. Images resized in this
> manner are cached so you only pay the ImageMagick tax once.
>
> Walter

Thanks Walter, I have already installed Dragonfly and it satisfies my
needs. Yet, I am still wondering how to define title and/or alt
attributes for the uploaded images. Any ideas? Thank you.

Walter Lee Davis

unread,
May 17, 2016, 6:54:01 PM5/17/16
to rubyonra...@googlegroups.com
You would define those in your view, just as for any other image type. http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag

Walter
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/5968243fd3986b5d1ca390fd6ac3e653%40ruby-forum.com.

W. M.

unread,
May 18, 2016, 1:49:34 PM5/18/16
to rubyonra...@googlegroups.com
Walter Davis wrote in post #1183529:
> You would define those in your view, just as for any other image type.
> http://apidock.com/rails/ActionView/Helpers/AssetTagHelper/image_tag
>
> Walter

I need to specify different alt/title attributes for the different
uploaded images. I guess I have to create an image model that specifies
an image + title or alt attribute as a string and then nest this model
inside another one (e.g. posts or articles etc..). I am still one week
into rails, but I believe this is the rails way to do it.

Walter Lee Davis

unread,
May 18, 2016, 5:00:14 PM5/18/16
to rubyonra...@googlegroups.com
The usual way that you do that is to define columns on the ActiveRecord model that has the image attached to it, and then when you use the image_tag helper, you can access those and use them.

image_tag @your_object.file.thumb('200x200#').url, alt: @your_object.alt, title: @your_object.title

If you haven't done so already, please do yourself a favor and invest a few days in working all the way through railstutorial.org. It's free to read and use on line, and it is the best way to learn the basics (and more importantly, the idioms) of Rails. It is an investment that will pay off for years to come.

Walter

> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/031108fdbac5b35e3c157f44080dea18%40ruby-forum.com.

W. M.

unread,
May 18, 2016, 5:19:27 PM5/18/16
to rubyonra...@googlegroups.com
Walter Davis wrote in post #1183553:
>> an image + title or alt attribute as a string and then nest this model
>> inside another one (e.g. posts or articles etc..). I am still one week
>> into rails, but I believe this is the rails way to do it.
>>
>
> The usual way that you do that is to define columns on the ActiveRecord
> model that has the image attached to it, and then when you use the
> image_tag helper, you can access those and use them.
>
> image_tag @your_object.file.thumb('200x200#').url, alt:
> @your_object.alt, title: @your_object.title
>
> If you haven't done so already, please do yourself a favor and invest a
> few days in working all the way through railstutorial.org. It's free to
> read and use on line, and it is the best way to learn the basics (and
> more importantly, the idioms) of Rails. It is an investment that will
> pay off for years to come.
>
> Walter

Thanks for all the information. Despite that the whole Rails / Ruby
system is very new to me, I sense the great power found in here. Things
can be achieved fast and accurately with far fewer lines of code than
other systems. Moreover, I simply like this framework.
Reply all
Reply to author
Forward
0 new messages