1 class SystemPicture < Peta::Item
4 has_many :speech_balloon_templates
7 validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
8 validates :width, :presence => true, :numericality => true, :natural_number => true
9 validates :height, :presence => true, :numericality => true, :natural_number => true
10 validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
11 validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
13 before_destroy :destroy_with_file
16 PictureIO.system_picture_io.delete self.filename
26 "#{self.id}.#{self.ext}"
34 '/system_pictures/' + filename
38 {:src => self.url, :width => self.width, :height => self.height}
42 tw, th = PettanImager.thumbnail_size(self.width, self.height)
43 {:src => self.url, :width => tw, :height => th}
55 'system_pictures.updated_at desc'
62 def self.list_json_opt
70 def self.show_json_opt
76 self.errors.add :base, 'illegal picture data'
80 SystemPicture.transaction do
83 res = PictureIO.system_picture_io.put(imager.binary, self.filename)
84 rescue PictureIO::Error
86 self.errors.add :base, I18n.t('picture_io.error')
87 raise ActiveRecord::Rollback
94 def self.store(imager)
95 attr = {:ext => imager.ext, :width => imager.width, :height => imager.height, :filesize => imager.filesize, :md5 => imager.md5}
96 sp = SystemPicture.modify_object(imager.md5, attr, 'md5')
101 def restore(subdir = nil)
102 PictureIO.system_picture_io.get self.filename, subdir