[reportlab-users] Implementation of drawImage anchoring
Robin Becker
robin at reportlab.com
Thu Aug 28 13:03:50 EDT 2008
Yoann Roman wrote:
> Yoann Roman wrote...
>> I've been reading (and re-reading) the doc for drawImage in Canvas, and
> I'm
>> pretty sure the implementation doesn't match what's described. To quote:
>>
>> [snip]
>>
>> I've got a patch for lib.boxstuff to get it to do what's stated in the
> doc,
>> but I wanted to verify whether the doc or the implementation was
> incorrect.
>> In my case, I needed what was stated in the doc.
>
> Anyone have any ideas on this? If the implementation is correct, what's the
> proper way to get the behavior described in the doc (i.e., centering an
> image within a box anchored at x, y)?
>
> Thanks,
>
So your original box corners are
(x,y), (x+width,y+width)
you wish to place the centre of the image at the centre of the box so use anchor
'c' and then use x+width*0.5, y+height*0.5; that should place the centre of the
image on the centre of the original box.
If the image or object doesn't support anchoring then you'll need to know the
size of the image or box in order to display it properly using some other anchor
point. It seems that drawImage does so you should be OK here.
--
Robin Becker
More information about the reportlab-users
mailing list