1 class SystemPicture < Pettanr::Item
3 has_many :balloon_templates
6 validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
7 validates :width, :presence => true, :numericality => true, :natural_number => true
8 validates :height, :presence => true, :numericality => true, :natural_number => true
9 validates :filesize, :presence => true, :numericality => {:greater_than => 0, :less_than_or_equal_to => 2000000}, :natural_number => true
10 validates :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
12 before_destroy :destroy_with_file
15 PictureIO.system_picture_io.delete self.filename
25 "#{self.id}.#{self.ext}"
33 '/system_pictures/' + filename
37 {:src => self.url, :width => self.width, :height => self.height}
41 tw, th = PettanImager.thumbnail_size(self.width, self.height)
42 {:src => self.url, :width => tw, :height => th}
54 'system_pictures.updated_at desc'
61 def self.list_json_opt
69 def self.show_json_opt
75 self.errors.add :base, 'illegal picture data'
79 SystemPicture.transaction do
82 res = PictureIO.system_picture_io.put(imager.binary, self.filename)
83 rescue PictureIO::Error
85 self.errors.add :base, I18n.t('picture_io.error')
86 raise ActiveRecord::Rollback
93 def self.store(imager)
94 attr = {:ext => imager.ext, :width => imager.width, :height => imager.height, :filesize => imager.filesize, :md5 => imager.md5}
95 sp = SystemPicture.modify_object(imager.md5, attr, 'md5')
100 def restore(subdir = nil)
101 PictureIO.system_picture_io.get self.filename, subdir