I used to get an image from the frontend and store it in the backend.
How can I compress that image before storing it to the database?
Is there any gem for compressing an image?
or any other way to do that?
Take a look at carrierwave gem. It is a wrapper for ImageMagick, that lets you process uploaded files before storing them (e.g. resize, convert, optimize etc).
Related
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
I need to read document texts with ruby and then perform some operations on their contents. Some of these documents include images that I need to upload to my server and later show the data with images. Any idea on how I can achieve this?
I'm thinking of using doc_ripper/docsplit, but ripper doesn't talk about images extraction, and docsplit seems to only take a screenshot of the entire page.
If this is not possible, I am fine with a way to recover the image file name in the right position, so then I can extract the file and upload it manually.
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 want do same working like php timthumb do in ror I tried gems but not found result as I want.
Images are taking much time to load.
for example code in php :
Can check what I required on :
http://www.darrenhoyt.com/demo/timthumb/
I want same way in ror?
You can try minimagick gem to compress image size and quality.
For example:
image = MiniMagick::Image.open(YOUR_IMAGE)
image.resize "130x100" ## The thumbnail size
image.write(YOUR_THUMB)
When you upload an imagine you want to have different sized versions that have been processed from the original.
Carrier wave to upload the image and resize it
https://github.com/carrierwaveuploader/carrierwave
You can resize as documented here: Carrier Wave - Versions
To be more precise here are associated tutorials for what you want using carrierwave and various libs for the conversions: Image Dimensions
You can even change the image type to keep a standard and do more image processing with libraries. Here is how: Image Processing
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?