Sha256: a00c4fa89fc7453b7c86eb86661ad4be25eb852120e8a976521011a1aa6f31ed

Contents?: true

Size: 1.02 KB

Versions: 27

Compression:

Stored size: 1.02 KB

Contents

require 'rubygems'
require 'shellwords'
require 'image_size'


module Alchemy::Custom::Model::ElFinder

  # Represents default image handler.
  # It uses *mogrify* to resize images and *convert* to create thumbnails.
  class Image

    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

    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

    # of self.resize

    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 # of self.resize

  end # of class Image

end # of module ElFinder

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
alchemy-custom-model-0.1.6 lib/alchemy/custom/model/el_finder/image.rb
alchemy-custom-model-0.1.5 lib/alchemy/custom/model/el_finder/image.rb
alchemy-custom-model-0.1.4 lib/alchemy/custom/model/el_finder/image.rb
alchemy-custom-model-0.1.3 lib/alchemy/custom/model/el_finder/image.rb
alchemy-custom-model-0.1.2 lib/alchemy/custom/model/el_finder/image.rb
alchemy-custom-model-0.1.1 lib/alchemy/custom/model/el_finder/image.rb
alchemy-custom-model-0.1.0 lib/alchemy/custom/model/el_finder/image.rb