[reportlab-users] Standard graphics: (85w x 32h pixels)

Dinu Gherman reportlab-users@reportlab.com
Sat, 4 Jan 2003 12:11:10 +0100


Andy Robinson:

> That needs some explanation.
>
> The code Robin posted was generated by our visual drawing editor,
> which is currently commercial code, and which needs some extra
> hooks in the drawing.  It should nevertheless be runnable.
> What matters is the property assignments.
>
> However, our logo has a default size of 130x86 so you may need
> to place it within a larger rectangle or it will look kind of
> distorted...

Right, and as the editor won't let you do this "magically" (I believe)
you have to write that code yourself anyway! So what one really wants
is something more like the code below.

Regards,

Dinu


# rlicon.py

from reportlab.lib.corp import RL_CorpLogo
from reportlab.graphics.shapes import Drawing, Rect


class RL_WebIcon(Drawing):
     "A drawing for making RL logo icons of specific sizes for web 
pages."

     # Exercise: add customizable strings like "powered by" etc.!

     def __init__(self, width=400, height=200, *args, **kw):
         apply(Drawing.__init__, (self, width, height) + args, kw)
         self.width = width
         self.height = height
         frameRatio = (0.0 + width) / height

         # create ReportLab vector logo
         logo = RL_CorpLogo()
         logoRatio = (0.0 + logo.width) / logo.height

         # add a background, reusing logo background color
         rect = Rect(0, 0, width, height,
             strokeColor=logo.background,
             fillColor=logo.background,
             stroke=0,
             fill=1)
         self.add(rect)

         # center logo with appropriate ratio in desired frame
         if logoRatio < frameRatio:
             logo.width  = self.width/frameRatio*logoRatio
             logo.height = self.height
             logo.x = (self.width-logo.width)/2.0
         else:
             logo.width = self.width
             logo.height  = self.height/logoRatio*frameRatio
             logo.y = (self.height-logo.height)/2.0

         # add logo
         self.add(logo)


if __name__=="__main__":
     RL_WebIcon(85, 32).save(formats=['png'], outDir='.', 
fnRoot="rlicon")

--
Dinu C. Gherman
......................................................................
Make your own Bush speech: http://www.lemonbovril.co.uk/bushspeech