Class: Alchemy::Custom::Model::ElFinder::Image
- Inherits:
-
Object
- Object
- Alchemy::Custom::Model::ElFinder::Image
- Defined in:
- lib/alchemy/custom/model/el_finder/image.rb
Overview
Represents default image handler. It uses mogrify to resize images and convert to create thumbnails.
Class Method Summary collapse
- .resize(pathname, options = {}) ⇒ Object
- .size(pathname) ⇒ Object
-
.thumbnail(src, dst, options = {}) ⇒ Object
of self.resize.
Class Method Details
.resize(pathname, options = {}) ⇒ Object
21 22 23 24 |
# File 'lib/alchemy/custom/model/el_finder/image.rb', line 21 def self.resize(pathname, = {}) return nil unless File.exist?(pathname) system(::Shellwords.join(['mogrify', '-resize', "#{[:width]}x#{[:height]}!", pathname.to_s])) end |
.size(pathname) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'lib/alchemy/custom/model/el_finder/image.rb', line 12 def self.size(pathname) return nil unless File.exist?(pathname) s = ::ImageSize.new(File.open(pathname)).size.to_s s = nil if s.empty? return s rescue nil end |
.thumbnail(src, dst, options = {}) ⇒ Object
of self.resize
28 29 30 31 |
# File 'lib/alchemy/custom/model/el_finder/image.rb', line 28 def self.thumbnail(src, dst, = {}) return nil unless File.exist?(src) system(::Shellwords.join(['convert', '-resize', "#{[:width]}x#{[:height]}", '-background', 'white', '-gravity', 'center', '-extent', "#{[:width]}x#{[:height]}", src.to_s, dst.to_s])) end |