Skip to content

Commit 42533bf

Browse files
committed
Format code with PEP8
1 parent 7ef9c9a commit 42533bf

File tree

6 files changed

+24
-15
lines changed

6 files changed

+24
-15
lines changed

iftg/creators/creator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def get_image_dimensions(cls,
6868
@abstractmethod
6969
def _apply_noise(cls, noises: list[Noise], image: Image) -> Image:
7070
pass
71-
71+
7272
@classmethod
7373
@abstractmethod
7474
def _blend_colors(cls, bg_color: str, text_color: str, font_opacity: float) -> tuple[int, int, int]:

iftg/creators/image_creator.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def _create_base_image(cls,
4646
tuple[Image.Image, int]:
4747
A tuple containing the generated image and the top margin adjustment.
4848
"""
49-
49+
5050
text_dimensions = cls.get_text_dimensions(text, font)
5151
image_width, image_height = cls.get_image_dimensions(
5252
margins, text_dimensions)
@@ -68,7 +68,7 @@ def _create_base_image(cls,
6868
random_bg_part = background_img.crop((x1, y1, x2, y2))
6969

7070
image.paste(random_bg_part)
71-
71+
7272
# Draw the text on the image
7373
draw = ImageDraw.Draw(image)
7474
draw.text((margins[0], -text_dimensions[1]+margins[1]),
@@ -89,12 +89,12 @@ def _apply_noise(cls, noises: list[Noise], image: Image) -> Image:
8989
9090
Returns:
9191
Image: The image with the applied text, noise, blur, and rotation effects.
92-
"""
92+
"""
9393
# Loop through all given noises and add them to the image
9494
image = reduce(lambda img, noise: noise.add_noise(img), noises, image)
9595

9696
return image
97-
97+
9898
@classmethod
9999
def _blend_colors(cls, bg_color: str, text_color: str, font_opacity: float) -> tuple[int, int, int]:
100100
"""
@@ -108,7 +108,7 @@ def _blend_colors(cls, bg_color: str, text_color: str, font_opacity: float) -> t
108108
Returns:
109109
tuple: The blended color as an (R, G, B) tuple.
110110
"""
111-
111+
112112
bg_r, bg_g, bg_b = ImageColor.getrgb(bg_color)
113113
text_r, text_g, text_b = ImageColor.getrgb(text_color)
114114

@@ -164,7 +164,7 @@ def create_image(cls,
164164
The generated image with the applied text and effects.
165165
"""
166166
font = ImageFontManager.get_font(font_path, font_size)
167-
167+
168168
r, g, b = cls._blend_colors(background_color, font_color, font_opacity)
169169
image = cls._create_base_image(
170170
text, font, (r, g, b), background_color, margins, background_img)

iftg/generators/batches_images_generator.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,11 @@ def extend_list(lst, default_value):
8383

8484
# Check if all input lists have the same length
8585
list_lengths = [len(texts), len(noises), len(font_paths), len(font_sizes),
86-
len(font_colors), len(font_opacities), len(background_colors), len(margins),
86+
len(font_colors), len(font_opacities), len(
87+
background_colors), len(margins),
8788
len(dpi), len(img_names), len(img_formats),
88-
len(img_output_paths), len(txt_names), len(txt_formats),
89+
len(img_output_paths), len(
90+
txt_names), len(txt_formats),
8991
len(txt_output_paths), len(background_image_paths)]
9092
if len(set(list_lengths)) != 1:
9193
max_len = max(list_lengths)

main_test.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
BlurNoise, BrightnessNoise, DilateNoise, ElasticNoise, ErodeNoise,
1414
FlipNoise, GaussianNoise, PixelDropoutNoise, RotationNoise, ShadowNoise
1515
)
16-
16+
17+
1718
def main0():
18-
image = ImageCreator.create_image('Hello, world', './fonts/Arial.ttf', font_opacity=0.3)
19+
image = ImageCreator.create_image(
20+
'Hello, world', './fonts/Arial.ttf', font_opacity=0.3)
1921
image.save('opacity_img.png', **image.info)
2022

2123

@@ -91,7 +93,8 @@ def main4():
9193
start = time.time()
9294

9395
texts = ['Hello, World!']
94-
results = ImagesGenerator(texts=texts, font_path='fonts/Arial.ttf', font_opacity=0.2)
96+
results = ImagesGenerator(
97+
texts=texts, font_path='fonts/Arial.ttf', font_opacity=0.2)
9598
results.generate_images_with_text()
9699

97100
end = time.time()
@@ -106,4 +109,3 @@ def main5():
106109

107110
if __name__ == '__main__':
108111
main1()
109-

tests/test_creators/test_image_creator.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def test_create_base_image(mock_font, mock_image, text, margins, bg_color, font_
4545

4646
assert image == mock_image
4747
assert image.size == expected_size
48-
assert isinstance(image, MagicMock) # Changed from Image.Image since we're using a mock
48+
# Changed from Image.Image since we're using a mock
49+
assert isinstance(image, MagicMock)
4950

5051

5152
def test_invalid_font_path():
@@ -55,4 +56,4 @@ def test_invalid_font_path():
5556
text="Test",
5657
font_path="invalid_path",
5758
font_size=40
58-
)
59+
)

tests/test_generators/test_images_generator.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,22 @@
1414
def valid_texts():
1515
return ["Hello", "World"]
1616

17+
1718
@pytest.fixture
1819
def valid_font_path():
1920
return "tests/Arial.ttf"
2021

22+
2123
@pytest.fixture
2224
def valid_output_path(tmpdir):
2325
return str(tmpdir)
2426

27+
2528
@pytest.fixture
2629
def valid_font_opacity():
2730
return 1.0
2831

32+
2933
@pytest.fixture
3034
def valid_background_image_path():
3135
return "background.jpg"

0 commit comments

Comments
 (0)