OSDN Git Service

t#29505:md5 search wrote test on picture
[pettanr/pettanr.git] / app / models / picture.rb
index 9701cf8..a4b9e38 100644 (file)
@@ -52,6 +52,11 @@ class Picture < ActiveRecord::Base
     '/pictures/' + filename
   end
   
+  def opt_img_tag
+    tw, th = PettanImager.thumbnail_size(self.width, self.height)
+    {:src => self.url, :width => tw, :height => th}
+  end
+  
   def new_revision
     Picture.maximum(:revision, :conditions => ['original_picture_id = ?', self.original_picture_id]).to_i + 1
   end
@@ -69,6 +74,10 @@ class Picture < ActiveRecord::Base
     flag_reverse < 0 ? [''] : ['', 'v', 'h', 'vh']
   end
   
+  def self.find_by_md5 md5
+    r = Picture.find :all, :conditions => ['pictures.md5 = ?', md5], :order => 'pictures.updated_at desc'
+  end
+  
   def self.list_by_md5 md5, opid
     r = Picture.find :all, :conditions => ['pictures.md5 = ? and pictures.original_picture_id <> ?', md5, opid], :order => 'pictures.updated_at desc'
   end