Sha256: d64109c66cd63b889ea60e86986525add26d972d9a7356ce0615e698e5dd439f

Contents?: true

Size: 764 Bytes

Versions: 2

Compression:

Stored size: 764 Bytes

Contents

module HighFive
  module ImageHelper

    # replace the image at path `image` with a resized version of the image at `source`
    def replace_image(image_path, source_path)
      image = ChunkyPNG::Image.from_file(image_path)

      if (rmagick?)
        source = Magick::Image.read(source_path).first
        resized = source.scale(image.height, image.width)
        resized.write(image_path)
      else
        source = ChunkyPNG::Image.from_file(path)
        source.resize(image.height, image.width).save(image_path)
      end

    end

    private
    def rmagick?
      @rmagick ||= begin
        require "rmagick"
        puts "Using rmagick..."
        true
      rescue LoadError
        puts "using ChunkyPNG..."
        false
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
high_five-0.2.9 lib/high_five/image_helper.rb
high_five-0.2.8 lib/high_five/image_helper.rb