1 class SystemPicture < Peta::SystemResource
4 has_many :speech_balloon_templates
6 has_many :writing_formats
8 validates :ext, :presence => true, :length => {:maximum => 4}, :inclusion => {:in => ['png', 'jpeg', 'gif']}
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 :md5, :presence => true, :length => {:minimum => 32, :maximum => 32}
14 before_destroy :destroy_with_file
17 PictureIO.system_picture_io.delete self.filename
27 "#{self.id}.#{self.ext}"
35 '/system_pictures/' + filename
39 {:src => self.url, :width => self.width, :height => self.height}
43 tw, th = PettanImager.thumbnail_size(self.width, self.height)
44 {:src => self.url, :width => tw, :height => th}
57 self.errors.add :base, 'illegal picture data'
61 SystemPicture.transaction do
64 res = PictureIO.system_picture_io.put(imager.binary, self.filename)
65 rescue PictureIO::Error
67 self.errors.add :base, I18n.t('picture_io.error')
68 raise ActiveRecord::Rollback
75 def self.store(imager)
76 attr = {:ext => imager.ext, :width => imager.width, :height => imager.height, :filesize => imager.filesize, :md5 => imager.md5}
77 sp = SystemPicture.modify_object(imager.md5, attr, 'md5')
82 def restore(subdir = nil)
83 PictureIO.system_picture_io.get self.filename, subdir