Sha256: 6f87e8e008e0563b63d2365f0f0e116ad16cd06e9acc509c21061c99f98c1255

Contents?: true

Size: 976 Bytes

Versions: 1

Compression:

Stored size: 976 Bytes

Contents

# encoding: utf-8

require 'mini_magick'

module TBird
  class Processor
    attr_reader :image
    def initialize(file_blob)
      @file_blob = file_blob
      @image = MiniMagick::Image.read(file_blob)
      @tempfile = Tempfile.new(SecureRandom.uuid)
    end

    def process(&block)
      image.combine_options do |img|
        block.call(img) if block_given?
      end
      write_to_file
    end

    def write_to_file
      image.write @tempfile
      @tempfile
    end
    
    def original
      @file_blob
    end

    def resize(size)
      process do |img|
        img.resize size
      end
    end

    def thumbnail(thumbnail_size = Configuration.thumbnail_size)
      process do |img|
        img.auto_orient
        img.thumbnail "x#{thumbnail_size*2}"
        img.resize "#{thumbnail_size*2}x<"
        img.resize "50%"
        img.gravity "center"
        img.crop "#{thumbnail_size}x#{thumbnail_size}+0+0"
        img.quality 92
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
t_bird-0.0.4 lib/t_bird/processor.rb