1 class Picture < ActiveRecord::Base
2 belongs_to :original_picture
6 validates :original_picture_id, :presence => true, :numericality => true, :existence => true
7 validates :revision, :presence => true, :numericality => true
8 validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
\r
9 validates :width, :presence => true, :numericality => true, :natural_number => true
10 validates :height, :presence => true, :numericality => true, :natural_number => true
11 validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
12 validates :license_id, :presence => true, :numericality => true, :existence => true
13 validates :artist_id, :presence => true, :numericality => true, :existence => true
14 validates :artist_name, :presence => true
21 "#{self.id}.#{self.dext}"
29 Picture.maximum(:revision, :conditions => ['original_picture_id = ?', self.original_picture_id]).to_i + 1
41 rimg.flip.flop.to_blob
45 self.dext == 'png' and self.flag_gif_convert >= 0
48 def self.png_to_gif(data)
51 mgk = Magick::Image.from_blob(data).shift
61 flag_reverse < 0 ? [''] : ['', 'v', 'h', 'vh']
66 self.revision = self.new_revision
68 if res = self.store_picture(mgk)
70 if gifmgk = Picture.png_to_gif(mgk.to_blob)
71 res = self.store_picture(gifmgk)
81 def store_picture(mgk)
84 picdata = d.empty? ? mgk.to_blob : self.__send__(d, mgk)
85 res = PictureIO.picture_io.put(picdata, "#{self.id}.#{mgk.format}", d)
91 def restore(subdir = nil)
92 PictureIO.resource_picture_io.get self.filename, subdir
97 @flags = JSON.parse(self.settings) unless @flags
108 @flag_open = flags["open"] unless @flag_open
113 @flag_commercial = flags["commercial"] unless @flag_commercial
118 @flag_official = flags["official"] unless @flag_official
123 @flag_attribution = flags["attribution"] unless @flag_attribution
128 @flag_derive = flags["derive"] unless @flag_derive
133 @flag_thumbnail = flags["thumbnail"] unless @flag_thumbnail
138 @flag_gif_convert = flags["gif_convert"] unless @flag_gif_convert
143 @flag_reverse = flags["reverse"] unless @flag_reverse
148 @flag_resize = flags["resize"] unless @flag_resize
153 @flag_sync_vh = flags["sync_vh"] unless @flag_sync_vh
158 @flag_overlap = flags["overlap"] unless @flag_overlap