ImageBuilder
The ImageBuilder is a pen that draws on a bitmap of PDF canvas. Is it not a subclass of XierpaBuilder, by the API is made equivalent where possible.A typical example of the functionality as used e.g. within the a subclass of XierpaBuilder
Import
from xpyth.xierpa.builders.imagebuilder import ImageBuilder
Example
ib = ImageBuilder(e, result)
font = 'Productus-Medium'
width = 200
height = 80
fontsize = 36
rotation = 0.5
ib.setpagesize(width, height)
ib.setformat('png')
ib.setpath('./_images/_thumbnails/ib_example1')
ib.newcanvas()
ib.setcursor(0, 0)
ib.setcolor('yellow')
ib.rectangle(width, height)
ib.setcursor(20, height/2 + 12)
ib.setrotation(rotation)
ib.setcolor('red')
ib.setfont(font)
ib.setfontsize(fontsize)
ib.text('Hello world')
ib.close()
ImportError: Missing module: examples
The ImageBuilder class builds the page and answers the XHTML code to reach the page result. For PDF
that is a link with a PDF icon, for bitmap it is the <img> link itself.
An overview
The ImageBuilder class contains the following tags:| Open tag | Close tag | Attributes | Docstring or default value |
|---|---|---|---|
| addstyle | name style |
The addstyle method adds a named (name) style (style) to the builder.
|
|
| addstyles | styles |
The addstyles method adds dictionary of named (name) style (style) to the
builder.
|
|
| applystyle2canvas | style |
Apply the relevant values on the canvas and the current state. If style is omitted, then take the
current style on the stack
|
|
| begintransparancylayer | Begin a transparency layer'. CoreGraphics only. |
||
| br | |||
| circle | r |
||
| close | absolutepath alt border class_ h id name unique usemap visible w |
The close method closes the running image builder and writes the binary data to a file. If the
visible tag is set, then write a HTML <img/> or
<a>...</a> to the output, depending on the type of the created document. If the unique attribute is set, then use this value to add as a unique parameter to the image link, so the image will always load. If the unique is equal to True, then use the result of self.e.uniqueid() as value (There were problems with caching browser or proxy servers). Finally add the actual filename with the current extension (e.g. 'image.png' as parameter as well to make sure that the browser sees the link as an image. |
|
| currentstate | |||
| curveto | bcp1x bcp1y bcp2x bcp2y x y |
||
| drawtext | s |
Draw the text in the canvas with the current settings and move the cursor
|
|
| ellipse | rx ry |
||
| endtransparancylayer | End the opened transparency layer'. CoreGraphics only. |
||
| fillpath | |||
| fillstrokepath | |||
| get | param |
||
| getcanvas |
The getcanvas method answers the canvas of self. The default behaviour is to answer
self.canvas.
|
||
| getcolumnheight | h |
||
| getcolumnwidth | |||
| getcursor | |||
| getformat | |||
| getpath | unique |
||
| getpath2fspath | path |
The getpath2fspath method is a wrapper around e['domainroot'] +
self.e.path2basedpath(path). It answers full file system path name, expanding the based
path with the domain root. This way virtual domain paths can be mapped to the file system.
If the path is already a valid fspath, then answer it unaltered. |
|
| image | brightness contrast cropbox h opacity resizefilter src w x y |
Draw the image. If no x/y defined, then use cursor position
im.resize(size) => image
im.resize(size, filter) => image
Returns a resized copy of an image. The size argument gives the requested size in pixels, as a 2-tuple:
(width, height).
The filter argument can be one of
NEAREST (use nearest neighbour),
BILINEAR (linear interpolation in a 2x2 environment),
BICUBIC (cubic spline interpolation in a 4x4 environment), or
ANTIALIAS (a high-quality downsampling filter).
If omitted, or if the image has mode "1" or "P", it is set to ANTIALIAS.
resizealgoritms = {
0:Image.NEAREST,
1:Image.ANTIALIAS,
2:Image.BILINEAR,
3:Image.BICUBIC,
}
assert resizealgoritms.has_key(resize), ("ImageBuilder.image: %s, resizefilter must be 0,1,2 or 3 refering to
the methods NEAREST,ANTIALIAS,BILINEAR,BICUBIC. Default is 1." % resizefilter)
|
|
| line | h w |
||
| lineto | x y |
||
| movecursor | dx dy |
||
| need | dx dy |
||
| newcanvas | options |
Create PdfCanvas or PngCanvas based on the ImageBuilder format.
@options format specific options.
|
|
| newpage |
Start a new page and set the cursor to the topleft of the current column on the new page
|
||
| polygon | coords |
||
| popstyle |
The popstyle pops the current style and makes the next one on the style stack available.
|
||
| pushstyle | style |
||
| rectangle | h w |
||
| ruler | color stroke width |
||
| set | param value |
||
| setalign | align |
||
| setbgcolor | color |
||
| setcolor | color |
||
| setcolumn | h w x y |
||
| setcolumnheight | h |
||
| setcolumnwidth | w |
||
| setcursor | x y |
||
| setcursor2column |
Set cursor at top left of current column positions
|
||
| setfill | fill |
||
| setfont | font fontsize |
||
| setfontsize | fontsize |
||
| setformat | format |
||
| sethyphenation | hyphenation |
||
| setimagefit | imagefit |
||
| setlanguage | language |
||
| setleading | leading |
||
| setminhyphen | left right |
||
| setopacity | opacity |
||
| setpageoffset | x y |
||
| setpagesize | h w |
||
| setpath | path |
||
| setquality | quality |
||
| setrotation | rotation |
||
| setshadow | blur color dx dy opacity |
Set the shadow of drawing. If dx and dy are both 0, then disable shadow
drawing. Note: Only implemented in the CoreGraphics canvas |
|
| setstroke | stroke |
||
| setstrokecolor | color |
||
| setstrokeopacity | opacity |
||
| settarget | target |
||
| settitle | title |
||
| settoporigin | toporigin |
||
| settracking | tracking |
||
| setuser | user |
||
| setzoom | zoom |
||
| square | d |
||
| stringwidth | s |
||
| strokepath | |||
| tab | x |
||
| text | s |
The text method draws the text on the canvas at the current position.
|
|
| triangle | g h v |
||
| writeimgsrc | absolutepath alt border class_ h id name usemap w |
||
| writepdfdiv | absolutepath |
