MCPcopy Create free account
hub / github.com/PageBot/PageBot / Image

Class Image

Lib/pagebot/elements/image.py:29–1362  ·  view source on GitHub ↗

An Image element contains the reference to the binary image data. eId can be (unique) file path or eId. >>> from pagebot.toolbox.units import mm, p, point3D >>> from pagebot.filepaths import getResourcesPath >>> imageFilePath = '/images/peppertom.png' >>> imagePath = getResource

Source from the content-addressed store, hash-verified

27
28
29class Image(Element):
30 """An Image element contains the reference to the binary image data. eId can be
31 (unique) file path or eId.
32
33 >>> from pagebot.toolbox.units import mm, p, point3D
34 >>> from pagebot.filepaths import getResourcesPath
35 >>> imageFilePath = '/images/peppertom.png'
36 >>> imagePath = getResourcesPath() + imageFilePath
37 >>> from pagebot import getContext #pagebot.contexts.htmlcontext.htmlcontext import HtmlContext
38 >>> from pagebot.constants import A4
39 >>> from pagebot.document import Document
40 >>> from pagebot.conditions import *
41 >>> context = getContext()
42 >>> doc = Document(size=A4, padding=30, context=context)
43 >>> page = doc[1]
44 >>> e = Image(imagePath, xy=pt(220, 330), w=512, parent=page, conditions=[Fit2Sides()])
45 >>> e.xy # Position of the image
46 (220pt, 330pt)
47 >>> (e.w, e.h), e.size, (e.iw, e.ih) # Identical result, width is the lead.
48 ((512pt, 681.81pt), (512pt, 681.81pt), (398pt, 530pt))
49 >>> e.h = 800 # Width is proportionally calculated, height is the lead.
50 >>> e.size
51 (600.75pt, 800pt)
52 >>> e.h *= 1.5
53 >>> e.size, e._w, e._h
54 ((901.13pt, 1200pt), None, 1200pt)
55 >>> e.size = mm(50), p(100) # Disproportional size setting.
56 >>> e.size
57 (50mm, 100p)
58 >>> e.size = None # Force answering the original image size.
59 >>> e.size # Initialize from file.
60 (398pt, 530pt)
61 >>> page.w = mm(150)
62 >>> e.conditions = [Top2Top(), Fit2Width()] # Set new condition, fitting on page padding of 30pt.
63 >>> doc.solve()
64 Score: 2 Fails: 0
65 >>> e.w = 48 # Make the element into a thumbnail, scale the image to it.
66 >>> #e._scaleImage(doc.view)
67 """
68 """
69 >>> w, h = e.size # New scaled proportions
70 >>> w
71 48pt
72 >>> round(h)
73 64pt
74 """
75
76 def __init__(self, path=None, alt=None, name=None, w=None, h=None,
77 size=None, cssSize=None, cssRepeat=None, z=0, mask=None, imo=None,
78 proportional=True, index=1, scaleImage=True, resolutionFactor=None,
79 scaleType=None, **kwargs):
80 Element.__init__(self, **kwargs)
81 """Initializes the self.im and self.ih sizes of the image file, defined
82 by path. If the path does not exist, then self.im = self.ih = pt(0)
83 This calls self.initImageSize() to set self.im and slef.ih from the
84 image file size.
85
86 If path is omitted or file does not exist, a gray rectangle with a

Callers 1

newImageFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected