I'm using paperclip to allow user to upload images and I want to convert an image into jpg/png only if it's a tiff image.
I am using the following code in my image.rb:
validates_attachment_presence :data
validates_attachment_content_type :data,
:content_type => ['image/jpeg', 'image/pjpeg',
'image/jpg', 'image/png', 'image/tif', 'image/gif'], :message => "has to be in a proper format"
I would like to know if it is possible to convert tiff images into jpg or png when uploading them.
Thanks a lot
Finally found a solution. Thought it might be helpful to somebody else.
In the image.rb, enter the following lines of code:
:styles => {
:thumb => ["150x172#",:jpg],
:large => ["100%", :jpg]
}
This will create 2 additional folders in the main image folder, thumb
and large
. If you want to display the images (which were tiff originally), simply display the jpeg version found in the 'large' folder.
Note that the original tiff images will still be stored in the 'original' folder under the main image folder.
Cheers
Tanya your solution is good. However if you don't care about the file type, you can store all images as jpg by passing the :original option as well. Example:
:styles => {
....
:original => ["100%", :jpg]
}
That will help ensure nowhere where the file is called will you run into issues.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With