| 1 |
|
| 2 |
require 'skin' |
| 3 |
|
| 4 |
module Plugin::Skin |
| 5 |
class Image < Diva::Model |
| 6 |
extend Memoist |
| 7 |
|
| 8 |
include Diva::Model::PhotoMixin |
| 9 |
|
| 10 |
register :skin_image, name: 'skin image' |
| 11 |
|
| 12 |
field.string :path, required: true |
| 13 |
|
| 14 |
def self.[](path) |
| 15 |
@store ||= Hash.new{|h,k| h[k] = new(path: k) } |
| 16 |
@store[path] |
| 17 |
end |
| 18 |
|
| 19 |
memoize def uri |
| 20 |
Diva::URI.new(scheme: 'file'.freeze, path: path) |
| 21 |
end |
| 22 |
|
| 23 |
:Pixbuf を返す。 |
| 24 |
|
| 25 |
(px) |
| 26 |
さ(px) |
| 27 |
|
| 28 |
ファイルシステムから画像が見つかった場合 |
| 29 |
def pixbuf(width:, height:) |
| 30 |
result = pixbuf_cache[[width, height].hash] |
| 31 |
if result |
| 32 |
result |
| 33 |
else |
| 34 |
width, height = width.to_i, height.to_i |
| 35 |
pixbuf_cache_set(GdkPixbuf::Pixbuf.new(file: uri.path, width: width, height: height), width: width, height: height) |
| 36 |
end |
| 37 |
end |
| 38 |
end |
| 39 |
end |