Class: Callisto::Thumbnail
- Inherits:
-
Object
- Object
- Callisto::Thumbnail
- Defined in:
- lib/callisto/thumbnail.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#crop ⇒ Object
Returns the value of attribute crop.
- #extension ⇒ Object
-
#file_path ⇒ Object
Returns the value of attribute file_path.
-
#flag ⇒ Object
Returns the value of attribute flag.
-
#name ⇒ Object
Returns the value of attribute name.
-
#prefix ⇒ Object
writeonly
Sets the attribute prefix.
- #public_path ⇒ Object
-
#quality ⇒ Object
writeonly
Sets the attribute quality.
-
#root_path ⇒ Object
writeonly
Sets the attribute root_path.
-
#size ⇒ Object
writeonly
Sets the attribute size.
Instance Method Summary collapse
- #fixed_size=(val) ⇒ Object
- #geometry ⇒ Object
-
#initialize(args = {}) ⇒ Thumbnail
constructor
A new instance of Thumbnail.
- #max_size=(val) ⇒ Object
- #min_size=(val) ⇒ Object
- #save ⇒ Object
- #save_path ⇒ Object
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
#args ⇒ Object
Returns the value of attribute args.
8 9 10 |
# File 'lib/callisto/thumbnail.rb', line 8 def args @args end |
#crop ⇒ Object
Returns the value of attribute crop.
9 10 11 |
# File 'lib/callisto/thumbnail.rb', line 9 def crop @crop end |
#extension ⇒ Object
47 48 49 |
# File 'lib/callisto/thumbnail.rb', line 47 def extension @extension || Callisto.configuration.thumbnail_extension || File.extname(file_path) end |
#file_path ⇒ Object
Returns the value of attribute file_path.
8 9 10 |
# File 'lib/callisto/thumbnail.rb', line 8 def file_path @file_path end |
#flag ⇒ Object
Returns the value of attribute flag.
8 9 10 |
# File 'lib/callisto/thumbnail.rb', line 8 def flag @flag end |
#name ⇒ Object
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
10 11 12 |
# File 'lib/callisto/thumbnail.rb', line 10 def prefix=(value) @prefix = value end |
#public_path ⇒ Object
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
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
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
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 |
#geometry ⇒ Object
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 |
#save ⇒ Object
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_path ⇒ Object
35 36 37 |
# File 'lib/callisto/thumbnail.rb', line 35 def save_path File.join(root_path, prefix, name) end |