Sha256: 27b4f061c3ee031453027163345fc97cb930144f9a1596ca59efb7e2e2452967

Contents?: true

Size: 774 Bytes

Versions: 17

Compression:

Stored size: 774 Bytes

Contents

module HighFive
  module ImageHelper

    # replace the image at image_path with a resized version of the image at source_path
    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(source_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

17 entries across 17 versions & 1 rubygems

Version Path
high_five-0.3.15 lib/high_five/image_helper.rb
high_five-0.3.14 lib/high_five/image_helper.rb
high_five-0.3.13 lib/high_five/image_helper.rb
high_five-0.3.12 lib/high_five/image_helper.rb
high_five-0.3.11 lib/high_five/image_helper.rb
high_five-0.3.10 lib/high_five/image_helper.rb
high_five-0.3.9 lib/high_five/image_helper.rb
high_five-0.3.8 lib/high_five/image_helper.rb
high_five-0.3.7 lib/high_five/image_helper.rb
high_five-0.3.6 lib/high_five/image_helper.rb
high_five-0.3.5 lib/high_five/image_helper.rb
high_five-0.3.4 lib/high_five/image_helper.rb
high_five-0.3.3 lib/high_five/image_helper.rb
high_five-0.3.2 lib/high_five/image_helper.rb
high_five-0.3.1 lib/high_five/image_helper.rb
high_five-0.3.0 lib/high_five/image_helper.rb
high_five-0.2.10 lib/high_five/image_helper.rb