Use both :at and :position/:vposition for images #285

Closed
systemed opened this Issue Oct 8, 2011 · 4 comments

Projects

None yet

4 participants

@systemed

At present, if a placed image is :at[x,y], none of the other image position options are read.

It would be nice to be able to use something like

image "file.png" :at=>[300,100], :position=>center, :vposition=>center

whereby the centre of the image, rather than the top left, would be positioned at 300,100.

Prawn has already read the image dimensions when it comes to determining the placement, so it can do this more efficiently than the calling program.

(Incidentally, thanks for the quick and excellent response to #281!)

@systemed

Adding the following code to lib/prawn/images.rb at line 122 works:

    case options[:position]
    when :center
      x-=w/2
    when :right
      x-=w
    end
    case options[:vposition]
    when :center
      y+=h/2
    when :bottom
      y+=h
    end

(apologies - haven't got my head around git enough to send a pull request yet but will try for next time :) )

@practicingruby
prawnpdf member

This is a neat idea, but I feel like the right solution is for us to come up with a unified API for positioning box-like content, rather than adding new special cases to each component.

Sorry we never responded to you about this, the project died down for a while. The good news is that we're now active again, so your contributions would be welcome!

@practicingruby practicingruby removed the stale label Mar 17, 2014
@packetmonkey

Adding myself to the issue

@mirelon

I created a fork with your code: https://github.com/mirelon/prawn/tree/patch-1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment