Commit e7cbaa45

mo k <m@mokhan.ca>
2011-09-27 02:31:21
update carrierwave settings to format file sizes when uploaded.
1 parent 8091bc5
app/uploaders/image_uploader.rb
@@ -5,6 +5,7 @@ class ImageUploader < CarrierWave::Uploader::Base
   # Include RMagick or ImageScience support:
   include CarrierWave::RMagick
   # include CarrierWave::ImageScience
+  include CarrierWave::MimeTypes
 
   # Choose what kind of storage to use for this uploader:
   # storage :file
@@ -27,8 +28,14 @@ class ImageUploader < CarrierWave::Uploader::Base
   # def default_url
   #   "/images/fallback/" + [version_name, "default.png"].compact.join('_')
   # end
-
+  #
   # Process files as they are uploaded:
+
+  process :set_content_type
+  # process :resize_to_fit => [420, 300]
+  process :resize_to_fit => [560, 400]
+  # process :resize_to_fit => [140, 100]
+  process :convert => 'png'
   # process :scale => [200, 300]
   #
   # def scale(width, height)
@@ -37,18 +44,21 @@ class ImageUploader < CarrierWave::Uploader::Base
 
   # Create different versions of your uploaded files:
   version :thumb do
-    process :resize_to_limit => [300, 139]
+    process :resize_to_fill => [140, 100]
   end
 
   # Add a white list of extensions which are allowed to be uploaded.
   # For images you might use something like this:
-  # def extension_white_list
-  #   %w(jpg jpeg gif png)
-  # end
+  def extension_white_list
+    %w(jpg jpeg gif png)
+  end
 
   # Override the filename of the uploaded files:
   # def filename
   #   "something.jpg" if original_filename
   # end
+  def filename
+    super.chomp(File.extname(super)) + '.png'
+  end
 
 end
app/views/categories/show.html.erb
@@ -8,7 +8,7 @@
   <% @creations.reverse.each do |creation| %>
     <div class="product_box">
       <h2><%= creation.name %></h2>
-      <a href="<%= url_for creation %>"> <%= image_tag creation.image_url.to_s,  :alt => creation.name %> </a>
+      <a href="<%= url_for creation %>"> <%= image_tag creation.image.thumb.url, :alt => creation.name %> </a>
       <p><%= creation.short_story %> <%= link_to 'more', creation %></p>
     </div>
   <% end %>
app/views/creations/index.html.erb
@@ -9,7 +9,7 @@
 
   <% @creations.reverse.each do |creation| %>
     <h2><%= creation.name %></h2>
-    <a href="<%= url_for creation %>"><%= image_tag creation.image_url.to_s, :class => "photo", :alt => creation.name %></a>
+    <a href="<%= url_for creation %>"><%= image_tag creation.image.thumb.url, :class => "photo", :alt => creation.name %></a>
     <p><%= creation.short_story %> <%= link_to 'more', creation %></p>
   <% end %>
 
app/views/creations/mine.html.erb
@@ -11,7 +11,7 @@
   <% else %>
     <% @creations.reverse.each do |creation| %>
       <h2><%= creation.name %></h2>
-      <a href="<%= url_for creation %>"><%= image_tag creation.image_url.to_s, :class => "photo" %></a>
+      <a href="<%= url_for creation %>"><%= image_tag creation.image.thumb.url, :class => "photo" %></a>
       <p><%= creation.short_story %> <%= link_to 'more', creation %></p>
     <% end %>
   <% end %>
app/views/home/index.html.erb
@@ -11,7 +11,7 @@
   <% @creations.each do |creation| %>
     <div>
       <h2><%= creation.name %></h2>
-      <a href="<%= url_for creation %>"><%= image_tag creation.image_url.to_s, :alt => creation.name %></a>
+      <a href="<%= url_for creation %>"><%= image_tag creation.image.thumb.url, :alt => creation.name %></a>
       <p><%= creation.short_story %> <%= link_to 'more', creation %></p>
     </div>
   <% end %>
app/views/search/index.html.erb
@@ -14,7 +14,7 @@
 
   <% @creations.reverse.each do |creation| %>
     <h2><%= creation.name %></h2>
-    <a href="<%= url_for creation %>"><%= image_tag creation.image_url.to_s, :alt => creation.name %></a>
+    <a href="<%= url_for creation %>"><%= image_tag creation.image.thumb.url, :alt => creation.name %></a>
     <p><%= creation.short_story %> <%= link_to 'more', creation %></p>
   <% end %>
 
db/schema.rb
@@ -1,3 +1,4 @@
+# encoding: UTF-8
 # This file is auto-generated from the current state of the database. Instead
 # of editing this file, please use the migrations feature of Active Record to
 # incrementally modify your database, and then regenerate this schema definition.