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)
| 52 | |
| 53 | |
| 54 | def 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 | |
| 72 | class WNode: |