Class: ElFinderFtp::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/el_finder_ftp/image.rb

Overview

Represents default image handler. It uses mogrify to resize images and convert to create thumbnails.

Class Method Summary collapse

Class Method Details

.resize(pathname, options = {}) ⇒ Object



18
19
20
21
# File 'lib/el_finder_ftp/image.rb', line 18

def self.resize(pathname, options = {})
  return nil unless File.exist?(pathname)
  system( ::Shellwords.join(['mogrify', '-resize', "#{options[:width]}x#{options[:height]}!", pathname.to_s]) ) 
end

.size(pathname) ⇒ Object



11
12
13
14
15
16
# File 'lib/el_finder_ftp/image.rb', line 11

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
end

.thumbnail(src, dst, options = {}) ⇒ Object

of self.resize



23
24
25
26
# File 'lib/el_finder_ftp/image.rb', line 23

def self.thumbnail(src, dst, options = {})
  return nil unless File.exist?(src)
  system( ::Shellwords.join(['convert', '-resize', "#{options[:width]}x#{options[:height]}", '-background', 'white', '-gravity', 'center', '-extent', "#{options[:width]}x#{options[:height]}", src.to_s, dst.to_s]) ) 
end