myexperiment-hackers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myexperiment-hackers] [2598] trunk: removed dependency on flex_image pl


From: noreply
Subject: [myexperiment-hackers] [2598] trunk: removed dependency on flex_image plugin
Date: Fri, 3 Jun 2011 06:33:44 -0400 (EDT)

Revision
2598
Author
dgc
Date
2011-06-03 06:33:43 -0400 (Fri, 03 Jun 2011)

Log Message

removed dependency on flex_image plugin

Modified Paths

Removed Paths

Diff

Modified: trunk/app/controllers/pictures_controller.rb (2597 => 2598)


--- trunk/app/controllers/pictures_controller.rb	2011-06-01 16:02:46 UTC (rev 2597)
+++ trunk/app/controllers/pictures_controller.rb	2011-06-03 10:33:43 UTC (rev 2598)
@@ -6,6 +6,7 @@
 class PicturesController < ApplicationController
   before_filter :login_required, :except => [:index, :show]
   
+  before_filter :find_picture, : [:show]
   before_filter :find_pictures, : [:index]
   before_filter :find_picture_auth, : [:select, :edit, :update, :destroy]
   
@@ -36,21 +37,36 @@
   # GET /users/1/pictures/1
   # GET /pictures/1
   def show
-    size = params[:size] || "200x200"
-    size = size[0..-($1.length.to_i + 2)] if size =~ /[0-9]+x[0-9]+\.([a-z0-9]+)/ # trim file extension
+
+    matches = params[:size].match("([0-9]+)x([0-9]+).*") if params[:size]
+
+    default_size = 200
+    min_size     = 16
+    max_size     = 200
+
+    if matches
+
+      width  = matches[1].to_i
+      height = matches[2].to_i
+
+      if ((width < min_size) || (width > max_size) || (height < min_size) || (height > max_size))
+        width  = default_size
+        height = default_size
+      end
+
+    else
+      width  = 200
+      height = 200
+    end
     
-    id = params[:id].to_i
-
-    send_cached_data("public/pictures/show/#{size}/#{id}.jpg",
+    send_cached_data("public/pictures/show/#{width.to_i}x#{height.to_i}/#{params[:id].to_i}.jpg",
         :type => 'image/jpeg', :disposition => 'inline') {
 
-      find_picture
+      img = Magick::Image.from_blob(@picture.data).first
+      img = img.change_geometry("#{width}x#{height}>") do |c, r, i| i.resize(c, r) end
 
-      # resize and encode the picture
-      @picture.resize!(:size => size)
-      @picture.to_jpg!
-
-      @picture.data
+      img.format = "jpg"
+      img.to_blob
     }
 
   end
@@ -70,7 +86,7 @@
   # POST /users/1/pictures
   # POST /pictures
   def create
-    @picture = Picture.create(:data ="" params[:picture][:data], :user_id => current_user.id)
+    @picture = Picture.create(:data ="" params[:picture][:data].read, :user_id => current_user.id)
 
     respond_to do |format|
       if @picture.save

Modified: trunk/app/models/picture.rb (2597 => 2598)


--- trunk/app/models/picture.rb	2011-06-01 16:02:46 UTC (rev 2597)
+++ trunk/app/models/picture.rb	2011-06-03 10:33:43 UTC (rev 2598)
@@ -3,8 +3,8 @@
 # Copyright (c) 2007 University of Manchester and the University of Southampton.
 # See license.txt for details.
 
-#class Picture < ActiveRecord::Base
-class Picture < FlexImage::Model
+class Picture < ActiveRecord::Base
+
   validates_associated :owner
   
   validates_presence_of :user_id, :data
@@ -32,12 +32,4 @@
   def selected?
     owner.profile.avatar? and owner.profile.picture.id.to_i == id.to_i
   end
-  
-  #file_column :data, :magick => {
-  #  :versions => {
-  #    :small    => { :size => "50x50!" }, 
-  #    :medium   => { :size => "100x100!" },
-  #    :large => { :size => "200x200!" }
-  #  }
-  #}
 end

reply via email to

[Prev in Thread] Current Thread [Next in Thread]