Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Different file extensions for different versions

I am using carrierwave to upload images. I need my main image version to remain in its original format, but other versions to be converted to gif.

At the moment i am doing something like this:

 def filename
   change_ext_to_gif(super)
 end

 def change_ext_to_gif(ext)
   ext.chomp(File.extname(ext)) + ".gif"
 end

 version :preview do
   process :resize_to_fill => [60, 60]
   process :convert => "gif"
 end

 version :full do
   process :resize_to_limit => [320, 320]
   process :convert => "gif"
 end

 version :mobile do
   process :resize_to_limit => [72, 96]
   process :convert => "gif"
 end

Of course, this changes extension of my original file as well. Is there any way to solve this? I guess i need to override some methods in the version's blocks. But i was not able to figure out them (I tried overriding filename and url this helps but prevents version`s files from being deleted).

like image 281
miros Avatar asked Mar 13 '11 20:03

miros


People also ask

What are the 3 types of files?

The types of files recognized by the system are either regular, directory, or special. However, the operating system uses many variations of these basic types. All file types recognized by the system fall into one of these categories. However, the operating system uses many variations of these basic types.


1 Answers

You can ovvierde the filename that gets used per version like so:

 version :mobile do
   process :resize_to_limit => [72, 96]
   process :convert => "gif"
   def full_filename(for_file = model.logo.file)
     "fiename here"
   end
 end

So just leave the original filename as you'd like and then alter it per version. There are further examples on the wiki here:

https://github.com/jnicklas/carrierwave/wiki/How-To%3A-Move-version-name-to-end-of-filename%2C-instead-of-front

like image 151
Mario Visic Avatar answered Sep 22 '22 23:09

Mario Visic