Sha256: 523f57292c78b906672bb6e5f6ad9c3a7be8a5da3ed13862346086cf48ebe5f5

Contents?: true

Size: 1.14 KB

Versions: 8

Compression:

Stored size: 1.14 KB

Contents

# encoding: utf-8
# image.rb : Base class for image info objects
#
# Copyright September 2011, Brad Ediger. All rights reserved.
#
# This is free software. Please see the LICENSE and COPYING files for details.

require 'digest/sha1'

module Prawn
  module Images
    class Image
      # @group Extension API

      def calc_image_dimensions(options)
        w = options[:width] || width
        h = options[:height] || height

        if options[:width] && !options[:height]
          wp = w / width.to_f
          w = width * wp
          h = height * wp
        elsif options[:height] && !options[:width]
          hp = h / height.to_f
          w = width * hp
          h = height * hp
        elsif options[:scale]
          w = width * options[:scale]
          h = height * options[:scale]
        elsif options[:fit]
          bw, bh = options[:fit]
          bp = bw / bh.to_f
          ip = width / height.to_f
          if ip > bp
            w = bw
            h = bw / ip
          else
            h = bh
            w = bh * ip
          end
        end
        self.scaled_width = w
        self.scaled_height = h

        [w,h]
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
prawn-git-2.0.1 lib/prawn/images/image.rb
prawn-2.0.1 lib/prawn/images/image.rb
prawn-2.0.0 lib/prawn/images/image.rb
prawn-1.3.0 lib/prawn/images/image.rb
prawn-1.2.1 lib/prawn/images/image.rb
prawn-1.1.0 lib/prawn/images/image.rb
prawn-1.0.0 lib/prawn/images/image.rb
prawn-0.15.0 lib/prawn/images/image.rb