Is it possible to restyle a picture after getting uploaded in paperclip? - ruby-on-rails

if pictures are uploaded using one style, how can i change the style of the uploaded picture after the picture is already uploaded. say if i want to change from tiny or thumb to original?
Thanks,

If you specified for example two styles :thumb and :grid and uploaded image to it, then you already have three images by default: grid, thumb and original. So in your views you could just use <your attachment>.path(:thumb) or <your attachment>.path(:grid).
Anyway if you added some more styles to your model you should call rake paperclip:refresh:missing_styles.
Documentation

Related

Is it possible for Paperclip to generate a new image (with no source)?

I'm building an image based off of user input -- the background will either be an image or a color, and then a few other images may or may not be composed on top.
Checking through the paperclip docs, it mentions that you can use ImageMagik to post-process images, and that post-processing will never fire if it doesnt already have an image.
If I am able to make the imagemagik scripts to compose/color/resize an image, is there a way for it to generate the image, or will I need to include some sort of hackish pixel to upload (and then postprocess in to the image I want)?
ImageMagick can generate a starting image for you, consisting of a simple rectangle filled with a single color. For example, this will generate a 150x100 red image:
convert -size 150x100 xc:"#ff0000" starting_image.png
I would try the following:
Have a default image in my app's assets folder
If the model to be saved has no attachment then I would assign it the one mentioned above: a_model.image = File.open('...')
Then, upon save of the a_model the post-processing should take place normally

Image version on Carrierwave

I'm making an album section and after the user uploads the images, carrierwave is making some versions like :thumb and :full.
When showing all the albums I get the first image of the album and display as the album cover. The thing is, I'm having to resize the thumb image and it gets ugly, I'd like to know if I can make a version (:cover) only of the first image uploaded so I can call this version when showing albums, but only the first image, so I don't have to make this version for all the images since I'll just be using the first one.

Paperclip - Wrong image orientation

I'm using Paperclip 4.1.1 for images uploading. I store three sizes, original, medium and thumbnail. When I try to show the original images, some of them appear rotated to the left, and it happens randomly, because some others are displayed correctly. This does not happen with medium and thumbnail sizes. The funny fact is that if I open any original image url on a browser, it always displays correctly. Any thoughts?
EDIT:
According to this comment in the Paperclip Railscast, this behavior doesn't occur on processed images. As a workaround, I added a new Paperclip style big enough to meet my requirements.
Check this How to set Paperclip to process original image? this will help.
Adding original: {convert_options: '-strip'} in styles help

Compositing/flattening images in Rails with Paperclip

I'm building a Rails application where a user can upload an image which is automatically cropped to a certain size, then they can choose an overlay which is exactly the same size as the cropped image.
What I want to do is composite or flatten the two images and save it as a single image - I've looked at the Image Magick documentation, but I can't see how to apply the example they give:
composite -gravity center smile.gif rose: rose-over.png
to work with Paperclip.
Also, the example references two specific images, but I'm wondering how I can pass in a variable (the user uploaded image) instead?
I believe you want to use a paperclip processor.
Here is the high level description:
https://github.com/thoughtbot/paperclip#custom-attachment-processors
Here is a gist example of using composite (recommended here https://github.com/thoughtbot/paperclip/issues/978):
https://gist.github.com/708077

How to save cropped image of an image URL without saving the original image? (in Rails using Paperclip or other plug-ins)

Hi all
I have an app now showing photos from URL, not from my own database (file system).
For example, a photo from Facebook:
http://sphotos.ak.fbcdn.net/hphotos-ak-snc1/hs085.snc1/5041_98423808305_40796308305_1960517_6704612_n.jpg
I've added the crop function to get the cropping area (x,y,w,h) of the photo.
And now I'd like to save the cropped image from the URL (i.e. without downloading the original image to my database before cropping)
Is it even possible?
Or is there anyway to get the image into memory to process without saving it to database?
I've searched some questions here, but they all talk about how to save the crop of images which have been uploaded to the database by users.
Thank you very much in advance.
How do you imagine cropping works without access to the original image? The process would be like this:
Download the remote image to a /tmp as a temporary file (Tip: TempFile)
Crop the crap out of it
Save the cropped image with Paperclip to your DB
Remove the temporary file

Resources