Class FreedesktopThumbnailer
In: lib/cacher/freedesktopthumbnailer.rb
Parent: Cacher

Methods

cachedir   mangle   new   thumbnail  

Constants

SIZES = { 'normal' => '128x128', 'large' => '256x256', 'tiny' => '32x24'
SIZE_NAMES = SIZES.invert
CacheDirs = [File.join(ENV['HOME'], '.thumbnails'), '/tmp/thumbnails']

Attributes

size  [RW] 
sizename  [RW] 

Public Class methods

[Source]

    # File lib/cacher/freedesktopthumbnailer.rb, line 15
15:         def initialize(size)
16:                 if !/x/.match(size)
17:                         size = SIZES[size]
18:                 end
19:                 self.size = size
20:                 self.sizename = SIZE_NAMES[size] || size
21:                 super(CacheDirs)
22:                 FileUtils.mkdir_p(cachedir)
23:         end

Public Instance methods

[Source]

    # File lib/cacher/freedesktopthumbnailer.rb, line 29
29:         def cachedir
30:                 File.join(super, sizename) 
31:         end

[Source]

    # File lib/cacher/freedesktopthumbnailer.rb, line 25
25:         def mangle(filename)
26:                 super('file://' + filename) + '.png'
27:         end

[Source]

    # File lib/cacher/freedesktopthumbnailer.rb, line 33
33:         def thumbnail(file, format)
34:                 cached(file) do
35:                         img = Magick::Image.read(file).first
36:                         img.change_geometry!(size) { |cols, rows| img.thumbnail! cols, rows }
37:                         img.format = format.upcase
38:                         img.to_blob
39:                 end
40:         end

[Validate]