From fb3df9d94fa993b8b66b0477aa05c5e428ea2b71 Mon Sep 17 00:00:00 2001 From: Petr Hodina Date: Fri, 18 Oct 2024 16:14:33 +0200 Subject: [PATCH] Fix some of the issues to get it working --- image_pixels_source.py | 10 +++++----- placeholder2image.py | 4 ++-- string_pixels_source.py | 6 +++--- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/image_pixels_source.py b/image_pixels_source.py index 1aeb80f..49f8b8a 100644 --- a/image_pixels_source.py +++ b/image_pixels_source.py @@ -16,11 +16,11 @@ def load_as_binary_image(image_path): converting it to a binary one (== black&white), if it is not yet one. ''' - with Image.open(image_path) as img: - if img.mode != "1": - img = img.convert("L") - img = img.convert("1") - return img + img = Image.open(image_path) + if img.mode != "1": + img = img.convert("L") + img = img.convert("1") + return img class ImagePixelsSource(PixelsSource): ''' diff --git a/placeholder2image.py b/placeholder2image.py index 284f5e9..17167b2 100644 --- a/placeholder2image.py +++ b/placeholder2image.py @@ -182,10 +182,10 @@ def _drawPixel(self, footprint: pcbnew.FOOTPRINT, index: int, pos: (int, int)): def drawPixels(self): footprint = pcbnew.FOOTPRINT(self.pcb) - footprint.SetDescription(f"Replaced template - {self.pixels}") + footprint.SetLibDescription(f"Replaced template - {self.pixels}") footprint.SetLayer(self.placeholder.getLayer()) - footprint.SetPosition(pcbnew.wxPoint(self.first_pixel_pos[0], self.first_pixel_pos[1])) + footprint.SetPosition(pcbnew.VECTOR2I(self.first_pixel_pos[0], self.first_pixel_pos[1])) pos = (0, 0) pixel_i = 0 x_i = 0 diff --git a/string_pixels_source.py b/string_pixels_source.py index 968600e..02d7d54 100644 --- a/string_pixels_source.py +++ b/string_pixels_source.py @@ -18,12 +18,12 @@ class StringPixelsSource(PixelsSource): ''' def __init__(self, text: str): self.text = text - text_size = _FONT.getsize(text) - image_size = (text_size[0] + 2, text_size[1] + 2) + text_size = _FONT.getbbox(text) + image_size = (text_size[2] + 2, text_size[3] + 2) self.image = Image.new("RGBA", image_size, (0, 0, 0, 0)) draw = ImageDraw.Draw(self.image) draw.rectangle(((0, 0), image_size), fill="white") - draw.rectangle(((1, 1), text_size), fill="black") + draw.rectangle(((1, 1), (text_size[2], text_size[3])), fill="black") draw.text((1, -1), text, font=_FONT, spaceing=1) self.image = self.image.convert("L") self.image = self.image.convert("1")