I want to upload some images and crop that without losing their quality in ruby on rails.For uploading images i have seen gems like paperclip,refile and CarrierWave.Which one will be better ?
Choosing between CarrierWave, Paperclip and Refile can be difficult at
times, but I would always recommend CarrierWave. It is the most
powerful and customizable of the three. It keeps your code organized
and clean, and is easy to test.
Refile isn't ready for prime time yet as it is still experiencing
growth pains and has DoS issues, and Paperclip is fairly simplistic.
For more information please see this acrticle: Best Rails image uploader - Paperclip vs. Carrierwave vs. Refile
Related
Let's say I got a project which has something like a media pool. Basically I wanna be able to upload whatever file you could upload (images, videos, pdf, etc.).
I was thinking about going with refile since it supports on-the-fly-processing of images which is nice since there is going to be an image api that should let the user request the image in whatever size he needs.
BUT, how would I handle pdf uploads or video uploads(even video processing)?
Is there maybe a better alternative to refile?
Thank you very much!
First of all, file attachment libraries can generally upload any type of file. Most popular are Paperclip and CarrierWave. They give you the ability to process on upload, which is suitable for videos. However, they don't allow you to process on-the-fly.
Dragonfly and Refile are, on the other hand, designed for on-the-fly processing. An upside of Refile is its support for direct uploads. One downside of Refile is that you have to serve all files through its Rack app, so if you have videos uploaded on S3 which you won't process, you still need to pay the performance penalty on first non-cached render. An upside of Dragonfly is that it has much more advanced on-the-fly processing support, and it also allows you to process on upload.
Lastly, we come to Shrine. Shrine was designed for processing on upload, and it's the only library with native support for background jobs, which is especially useful for longer processing like video transcoding. Shrine also has a Transloadit integration, if you want to delegate processing to a 3rd-party service. But you can also get on-the-fly processing with Shrine, using services like Cloudinary or even hooking up Dragonfly (see this post). Shrine has support for direct uploads, like Refile. Some of the other notable features include: metadata support, logging, flexible file validation, resumable uploads, better security and other.
Since Shrine arguably has most features and flexibility than any other file attachment library, I would recommend going for it.
In Rails, while using the carrierwave gem, can we optimize images that are being uploaded? Optimize means compress and shrink the file size?
Yes, it is possible. You should write own image processor and use ImageMagick or MiniMagick command to optimize images as you wish.
For example here is article about optimization of images with MiniMagick.
The second way is related to using such gems as carrierwave-imageoptimizer it provide image optimization out of the box.
I am interested in building a Rails based system for handling the display and organization of large amounts of photos. This is sort of like Flickr but smaller. Each photo will have metadata associated with it. Photos will be shown in a selectable list and grid view. It would be nice to be able to load images as they are needed as well (as this would probably speed things up).
At the moment I have a test version of my database working by images loading from the assets/images directory but it is beginning to run slow when displaying several images (200-600 images). This is due to the way I have my view setup. I am using a straight loop to display the images in both list and grid layouts.
I also manually resized the thumbnails and a medium sized image from a full sized source image. I am investigating other resizing methods. Any advice is appreciated here as well.
As I am new to handling the images this way, could someone point me in a direction based on experience designing and implementing something like Flickr?
I am investigating the following tools:
Paperclip
http://railscasts.com/episodes/134-paperclip
Requirements: ImageMajick
attachment_fu
http://clarkware.com/blog/2007/02/24/file-upload-fu#FileUploadFu
Requirement: One of the following: ImageScience, RMagick, miniMagick, ImageMajick?
CarrierWave
http://cloudinary.com/blog/ruby_on_rails_image_uploads_with_carrierwave_and_cloudinary
http://cloudinary.com/blog/advanced_image_transformations_in_the_cloud_with_carrierwave_cloudinary
I'd go with Carrierwave anyday. It is very flexible and has lot of useful strategies. It generates it's on Uploader class and has all nifty and self explanatory features such as automatic generation of thumbnails (as specified by you), blacklisting, formatting image, size constraints etc; which you can put to your use.
This Railscast by Ryan Bates - http://railscasts.com/episodes/253-carrierwave-file-uploads is very useful, if you haven't seen it already.
Paperclip and CarrierWave are totally appropriate tools for the job, and the one you choose is going to be a matter of personal preference. They both have tons of users and active, ongoing development. The difference is whether you'd prefer to define your file upload rules in a separate class (CarrierWave), or if you'd rather define them inline in your model (Paperclip).
I prefer CarrierWave, but based on usage it's clear plenty of people feel otherwise.
Note that neither gem is going to do anything for your slow view with 200-600 images. These gems are just for handling image uploads, and don't help you with anything beyond that.
Note also that Rails is really pretty bad at handling file uploads and file downloads, and you should avoid this where possible by letting other services (a cdn, your web server, s3, etc) handle these for you. The central gotcha is that if you handle a file transfer with rails, your entire web application process is busy for the duration of the transfer. (For related discussion on this topic, see: Best Ruby on Rails Architecture for Image Heavy App).
I use carrierwave and would like to have GD2 process the images (cropping / resizing). ImageMagick and RMagic are good functionality wise but are to resource heavy.
I have searched around but was not able to find any good leads. I appreciate any suggestions.
Google's app engine has this speedy image resizing api which appears to perform significantly faster than the rails paperclip resizing alternative.
Anyone know of any rails/heroku friend image resizing api's that could work with paperclip to be a faster resizing solution?
Thanks
We've used Transloadit and it works well:
http://transloadit.com/
When you do images on heroku, you're usually storing them up on S3.
You can upload the file directly to S3, then use delayed job to process the file in the background. Your users will see a zippier/faster processing time.
Paperclip itself doesn't include image-resizing code; it simply plugs into tools like ImageMagick and MiniMagick. Have you tried some of these other engines?