MCPcopy Create free account
hub / github.com/KDE/krita / expandAndFormat

Function expandAndFormat

plugins/python/batch_exporter/Infrastructure.py:54–69  ·  view source on GitHub ↗

Draws the image with transparent background if `is_jpg == False`, otherwise with a white background. It's done in a single function, to avoid creating extra images

(img, margin=0, is_jpg=False)

Source from the content-addressed store, hash-verified

52
53
54def expandAndFormat(img, margin=0, is_jpg=False):
55 """
56 Draws the image with transparent background if `is_jpg == False`, otherwise with a white background.
57 It's done in a single function, to avoid creating extra images
58 """
59 if not margin and not is_jpg:
60 return img
61 corner = QSize(margin, margin)
62 white = QColor(255, 255, 255) if is_jpg else QColor(255, 255, 255, 0)
63 canvas = QImage(
64 img.size() + corner * 2, QImage.Format.Format_RGB32 if is_jpg else QImage.Format.Format_ARGB32
65 )
66 canvas.fill(white)
67 p = QPainter(canvas)
68 p.drawImage(margin, margin, img)
69 return canvas
70
71
72class WNode:

Callers 3

saveMethod · 0.85
saveCOAMethod · 0.85
saveCOASpriteSheetMethod · 0.85

Calls 7

QSizeClass · 0.50
QColorClass · 0.50
QImageClass · 0.50
QPainterClass · 0.50
sizeMethod · 0.45
fillMethod · 0.45
drawImageMethod · 0.45

Tested by

no test coverage detected