Class: ElFinderS3::Image

Inherits:
Object
  • Object
show all
Defined in:
lib/el_finder_s3/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


19
20
21
22
# File 'lib/el_finder_s3/image.rb', line 19

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


12
13
14
15
16
17
# File 'lib/el_finder_s3/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
end

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

of self.resize


26
27
28
29
30
31
32
33
34
35
# File 'lib/el_finder_s3/image.rb', line 26

def self.thumbnail(imgSourcePath, dst, options = {})
  image = MiniMagick::Image.open(imgSourcePath)
  image.combine_options do |c|
    c.thumbnail "#{options[:width]}x#{options[:height]}"
    c.background 'white'
    c.gravity 'center'
    c.extent "#{options[:width]}x#{options[:height]}"
  end
  dst.write(image)
end