### Home Classes Methods

### In Files

- lib/prawn/images/image.rb

### Parent

Object

### Methods

- #calc_image_dimensions

### Class/Module Index

Quicksearch

- Prawn
- Prawn::Configurable
- Prawn::Document
- Prawn::Document::BoundingBox
- Prawn::Document::ColumnBox
- Prawn::Document::GraphicsState
- Prawn::Document::Grid
- Prawn::Document::GridBox
- Prawn::Document::Internals
- Prawn::Document::Security
- Prawn::Document::Snapshot
- Prawn::Encoding
- Prawn::Errors
- Prawn::Font
- Prawn::Font::AFM
- Prawn::Font::DFont
- Prawn::Font::TTF
- Prawn::FontMetricCache
- Prawn::Graphics
- Prawn::Graphics::CapStyle
- Prawn::Graphics::Color
- Prawn::Graphics::Dash
- Prawn::Graphics::JoinStyle
- Prawn::Graphics::Patterns
- Prawn::Graphics::Transformation
- Prawn::Graphics::Transparency
- Prawn::ImageHandler
- Prawn::Images
- Prawn::Images::Image
- Prawn::Images::JPG
- Prawn::Images::PNG
- Prawn::Measurements
- Prawn::SoftMask
- Prawn::Stamp
- Prawn::SynchronizedCache
- Prawn::Table
- Prawn::Table::Cell
- Prawn::Table::Cell::Image
- Prawn::Table::Cell::InTable
- Prawn::Table::Cell::SpanDummy
- Prawn::Table::Cell::Subtable
- Prawn::Table::Cell::Text
- Prawn::Table::Cells
- Prawn::Table::ColumnWidthCalculator
- Prawn::Text
- Prawn::Text::Box
- Prawn::Text::Formatted
- Prawn::Text::Formatted::Box
- Prawn::Text::Formatted::Fragment
- Prawn::Text::Formatted::Parser
- Prawn::ThreadLocalCache
- PDF
- PDF::Core
- PDF::Core::Reference
- PDF::Core::Stream
- Arcfour
- Numeric

No matching classes.

# Prawn::Images::Image

### Public Instance Methods

calc_image_dimensions(options) click to toggle source

@group Extension API

    # File lib/prawn/images/image.rb, line 14
    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

[Validate]

Generated with the Darkfish Rdoc Generator 2.