<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>examples/image_position.rb</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -20,9 +20,11 @@ module Prawn
     # Options:
     # &lt;tt&gt;:at&lt;/tt&gt;:: the location of the top left corner of the image.
     # &lt;tt&gt;:position&lt;/tt&gt;::  One of (:left, :center, :right) or an x-offset
+    # &lt;tt&gt;:vposition&lt;/tt&gt;::  One of (:top, :center, :center) or an y-offset    
     # &lt;tt&gt;:height&lt;/tt&gt;:: the height of the image [actual height of the image]
     # &lt;tt&gt;:width&lt;/tt&gt;:: the width of the image [actual width of the image]
-    # &lt;tt&gt;:scale&lt;/tt&gt;:: scale the dimensions of the image proportionally   
+    # &lt;tt&gt;:scale&lt;/tt&gt;:: scale the dimensions of the image proportionally
+    # &lt;tt&gt;:fit&lt;/tt&gt;:: scale the dimensions of the image proportionally to fit inside [with,height]
     # 
     #   Prawn::Document.generate(&quot;image2.pdf&quot;, :page_layout =&gt; :landscape) do     
     #     pigs = &quot;#{Prawn::BASEDIR}/data/images/pigs.jpg&quot; 
@@ -51,7 +53,7 @@ module Prawn
     # (See also: Prawn::Images::PNG , Prawn::Images::JPG)
     # 
     def image(file, options={})     
-      Prawn.verify_options [:at,:position, :height, :width, :scale], options
+      Prawn.verify_options [:at, :position, :vposition, :height, :width, :scale, :fit], options
       
       if file.respond_to?(:read)
         image_content = file.read
@@ -86,6 +88,7 @@ module Prawn
 
       # find where the image will be placed and how big it will be  
       w,h = calc_image_dimensions(info, options)
+
       if options[:at]       
         x,y = translate(options[:at]) 
       else                  
@@ -118,8 +121,18 @@ module Prawn
         bounds.absolute_right - w
       when Numeric
         options[:position] + bounds.absolute_left
-      end       
-      
+      end
+      options[:vposition] ||= :top
+      y = case options[:vposition]
+      when :top
+        bounds.absolute_top
+      when :center
+        bounds.absolute_top - (bounds.height - h) / 2.0
+      when :bottom
+        bounds.absolute_bottom + h
+      when Numeric
+        bounds.absolute_top - options[:vposition]
+      end
       return [x,y]
     end
 
@@ -252,7 +265,6 @@ module Prawn
     end
 
     def calc_image_dimensions(info, options)
-      # TODO: allow the image to be aligned in a box
       w = options[:width] || info.width
       h = options[:height] || info.height
 
@@ -267,8 +279,20 @@ module Prawn
       elsif options[:scale] 
         w = info.width * options[:scale]
         h = info.height * options[:scale]
+      elsif options[:fit] 
+        bw, bh = options[:fit]
+        bp = bw / bh.to_f
+        ip = info.width / info.height.to_f
+        if ip &gt; bp
+          w = bw
+          h = bw / ip
+        else
+          h = bh
+          w = bh * ip
+        end
       end
-
+      info.scaled_width = w
+      info.scaled_height = h
       [w,h]
     end
 </diff>
      <filename>lib/prawn/images.rb</filename>
    </modified>
    <modified>
      <diff>@@ -14,7 +14,8 @@ module Prawn
     # of a PNG image that we need to embed them in a PDF
     class JPG 
       attr_reader :width, :height, :bits, :channels
-
+      attr_accessor :scaled_width, :scaled_height
+      
       JPEG_SOF_BLOCKS = %W(\xc0 \xc1 \xc2 \xc3 \xc5 \xc6 \xc7 \xc9 \xca \xcb \xcd \xce \xcf)
       JPEG_APP_BLOCKS = %W(\xe0 \xe1 \xe2 \xe3 \xe4 \xe5 \xe6 \xe7 \xe8 \xe9 \xea \xeb \xec \xed \xee \xef)
 </diff>
      <filename>lib/prawn/images/jpg.rb</filename>
    </modified>
    <modified>
      <diff>@@ -19,7 +19,8 @@ module Prawn
       attr_reader :width, :height, :bits
       attr_reader :color_type, :compression_method, :filter_method
       attr_reader :interlace_method, :alpha_channel
-
+      attr_accessor :scaled_width, :scaled_height
+      
       # Process a new PNG image
       #
       # &lt;tt&gt;:data&lt;/tt&gt;:: A string containing a full PNG file</diff>
      <filename>lib/prawn/images/png.rb</filename>
    </modified>
    <modified>
      <diff>@@ -17,7 +17,6 @@ describe &quot;the image() function&quot; do
     images = PDF::Inspector::XObject.analyze(output)
     # there should be 2 images in the page resources
     images.page_xobjects.first.size.should == 2
-
     # but only 1 image xobject
     output.scan(/\/Type \/XObject/).size.should == 1
   end  
@@ -36,5 +35,20 @@ describe &quot;the image() function&quot; do
     
     info.height.should == 453
   end
+  
+  it &quot;should fit inside the defined constraints&quot; do
+    info = @pdf.image @filename, :fit =&gt; [100,400]
+    info.scaled_width.should &lt;= 100
+    info.scaled_height.should &lt;= 400
+    
+    info = @pdf.image @filename, :fit =&gt; [400,100]
+    info.scaled_width.should &lt;= 400
+    info.scaled_height.should &lt;= 100
+    
+    info = @pdf.image @filename, :fit =&gt; [604,453]
+    info.scaled_width.should == 604
+    info.scaled_height.should == 453
+  end
+  
 end
 </diff>
      <filename>spec/images_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>cd04282be99807674d796e466e1512ec8f4a81d0</id>
    </parent>
    <parent>
      <id>566de576dbf32915ed07647f982c9e0f10ef494c</id>
    </parent>
  </parents>
  <author>
    <name>Gregory Brown</name>
    <email>gregory.t.brown@gmail.com</email>
  </author>
  <url>http://github.com/sandal/prawn/commit/0c97cc776ab65adc50e317768a6c3cc246cca9ed</url>
  <id>0c97cc776ab65adc50e317768a6c3cc246cca9ed</id>
  <committed-date>2008-10-31T06:01:24-07:00</committed-date>
  <authored-date>2008-10-31T06:01:24-07:00</authored-date>
  <message>Merge branch 'master' of git://github.com/trym/prawn</message>
  <tree>186f34f0ba75e048d96f2414c073e7a67be9831a</tree>
  <committer>
    <name>Gregory Brown</name>
    <email>gregory.t.brown@gmail.com</email>
  </committer>
</commit>
