Class: Callisto::Thumbnail

Inherits:
Object
  • Object
show all
Defined in:
lib/callisto/thumbnail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = {}) ⇒ Thumbnail

Returns a new instance of Thumbnail.



12
13
14
15
16
17
# File 'lib/callisto/thumbnail.rb', line 12

def initialize(args = {})
  args.each do |name, value|
    self.send("#{name}=", value)
  end
  self.name = args
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



8
9
10
# File 'lib/callisto/thumbnail.rb', line 8

def args
  @args
end

#cropObject

Returns the value of attribute crop.



9
10
11
# File 'lib/callisto/thumbnail.rb', line 9

def crop
  @crop
end

#extensionObject



47
48
49
# File 'lib/callisto/thumbnail.rb', line 47

def extension
  @extension || Callisto.configuration.thumbnail_extension || File.extname(file_path)
end

#file_pathObject

Returns the value of attribute file_path.



8
9
10
# File 'lib/callisto/thumbnail.rb', line 8

def file_path
  @file_path
end

#flagObject

Returns the value of attribute flag.



8
9
10
# File 'lib/callisto/thumbnail.rb', line 8

def flag
  @flag
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/callisto/thumbnail.rb', line 9

def name
  @name
end

#prefix=(value) ⇒ Object (writeonly)

Sets the attribute prefix

Parameters:

  • value

    the value to set the attribute prefix to.



10
11
12
# File 'lib/callisto/thumbnail.rb', line 10

def prefix=(value)
  @prefix = value
end

#public_pathObject



39
40
41
# File 'lib/callisto/thumbnail.rb', line 39

def public_path
  File.join((@public_path || Callisto.configuration.thumbnail_public_path).to_s, name)
end

#quality=(value) ⇒ Object (writeonly)

Sets the attribute quality

Parameters:

  • value

    the value to set the attribute quality to.



10
11
12
# File 'lib/callisto/thumbnail.rb', line 10

def quality=(value)
  @quality = value
end

#root_path=(value) ⇒ Object (writeonly)

Sets the attribute root_path

Parameters:

  • value

    the value to set the attribute root_path to.



10
11
12
# File 'lib/callisto/thumbnail.rb', line 10

def root_path=(value)
  @root_path = value
end

#size=(value) ⇒ Object (writeonly)

Sets the attribute size

Parameters:

  • value

    the value to set the attribute size to.



10
11
12
# File 'lib/callisto/thumbnail.rb', line 10

def size=(value)
  @size = value
end

Instance Method Details

#fixed_size=(val) ⇒ Object



57
58
59
60
# File 'lib/callisto/thumbnail.rb', line 57

def fixed_size=(val)
  self.min_size = val
  self.crop = true
end

#geometryObject



73
74
75
76
# File 'lib/callisto/thumbnail.rb', line 73

def geometry
  task = Shell.new("identify", "-format \"%wx%h\" #{save_path}")
  task.run
end

#max_size=(val) ⇒ Object



67
68
69
70
71
# File 'lib/callisto/thumbnail.rb', line 67

def max_size=(val)
  self.size = val
  self.flag = "\\>"
  self.crop = true
end

#min_size=(val) ⇒ Object



62
63
64
65
# File 'lib/callisto/thumbnail.rb', line 62

def min_size=(val)
  self.flag = "^"
  self.size = val
end

#saveObject



24
25
26
27
28
29
30
31
32
33
# File 'lib/callisto/thumbnail.rb', line 24

def save
  location = File.join(root_path, prefix)
  if !File.exist?(save_path)
    FileUtils.mkdir_p(location) unless File.directory?(location)
    task = Shell.new("convert", "#{file_path} -strip -quality #{quality} -resize #{size}#{flag} #{crop} #{save_path}")
    pid = Callisto::Pool.instance << task
    Callisto::Pool.instance.wait(pid)
  end
  public_path
end

#save_pathObject



35
36
37
# File 'lib/callisto/thumbnail.rb', line 35

def save_path
  File.join(root_path, prefix, name)
end