Skip to content

Commit

Permalink
fixed typing issues and bumped version to 0.3.7
Browse files Browse the repository at this point in the history
  • Loading branch information
shahriyardx committed Sep 25, 2024
1 parent 8a40896 commit cee1204
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion easy_pil/_version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from collections import namedtuple

__version__ = "0.3.7"
__version__ = "0.3.8"

VersionInfo = namedtuple("VersionInfo", "major minor macro release")

Expand Down
42 changes: 22 additions & 20 deletions easy_pil/editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ def image_bytes(self) -> BytesIO:
def close(self):
self.image.close()

def resize(self, size: Tuple[int, int], crop=False) -> Editor:
def resize(self, size: Tuple[float, float], crop=False) -> Editor:
"""Resize image
Parameters
----------
size : Tuple[int, int]
size : Tuple[float, float]
New Size of image
crop : bool, optional
Crop the image to bypass distortion, by default False
Expand Down Expand Up @@ -244,7 +244,7 @@ def paste(

def text(
self,
position: Tuple[int, int],
position: Tuple[float, float],
text: str,
font: Optional[Union[ImageFont.FreeTypeFont, Font]] = None,
color: Color = "black",
Expand All @@ -256,7 +256,7 @@ def text(
Parameters
----------
position : Tuple[int, int]
position : Tuple[float, float]
Position to draw text.
text : str
Text to draw
Expand Down Expand Up @@ -297,7 +297,7 @@ def text(

def multi_text(
self,
position: Tuple[int, int],
position: Tuple[float, float],
texts: List[Text],
space_separated: bool = True,
align: Literal["left", "center", "right"] = "left",
Expand All @@ -306,7 +306,7 @@ def multi_text(
Parameters
----------
position : Tuple[int, int]
position : Tuple[float, float]
Position to draw text
texts : List[Text]
List of texts
Expand All @@ -323,16 +323,16 @@ def multi_text(
if align == "right":
total_width = 0

for text in texts:
total_width += text.font.getlength(text.text)
for t in texts:
total_width += t.font.getlength(t.text)

position = (int(position[0] - total_width), int(position[1]))

if align == "center":
total_width = 0

for text in texts:
total_width += text.font.getlength(text.text)
for t in texts:
total_width += t.font.getlength(t.text)

position = (int(position[0] - (total_width / 2)), int(position[1]))

Expand All @@ -353,7 +353,7 @@ def multi_text(

def rectangle(
self,
position: Tuple[int, int],
position: Tuple[float, float],
width: float,
height: float,
fill: Optional[Color] = None,
Expand All @@ -366,7 +366,7 @@ def rectangle(
Parameters
----------
position : Tuple[int, int]
position : Tuple[float, float]
Position to draw rectangle
width : float
Width of rectangle
Expand Down Expand Up @@ -444,6 +444,9 @@ def bar(
radius : int, optional
Radius of the bar, by default 0
"""
if percentage == 0:
return self

if color:
fill = color

Expand All @@ -452,7 +455,6 @@ def bar(
"RGBA", (int(max_width), int(height)), (0, 0, 0, 0)
)
mask = PilImage.new("L", (int(max_width), int(height)), 0)

main_draw = ImageDraw.Draw(main)

if percentage > 100 or percentage < 0:
Expand Down Expand Up @@ -486,7 +488,7 @@ def bar(
)

final = PilImage.composite(main, bg, mask)
self.paste(final, (position))
self.paste(final, position)

main.close()
final.close()
Expand All @@ -497,7 +499,7 @@ def bar(

def rounded_bar(
self,
position: Tuple[int, int],
position: Tuple[float, float],
width: Union[int, float],
height: Union[int, float],
percentage: float,
Expand All @@ -509,7 +511,7 @@ def rounded_bar(
Parameters
----------
position : Tuple[int, int]
position : Tuple[float, float]
Position to draw rounded bar
width : Union[int, float]
Width of the bar
Expand Down Expand Up @@ -544,7 +546,7 @@ def rounded_bar(

def ellipse(
self,
position: Tuple[int, int],
position: Tuple[float, float],
width: float,
height: float,
fill: Optional[Color] = None,
Expand All @@ -556,7 +558,7 @@ def ellipse(
Parameters
----------
position : Tuple[int, int]
position : Tuple[float, float]
Position to draw ellipse
width : float
Width of ellipse
Expand Down Expand Up @@ -617,7 +619,7 @@ def polygon(

def arc(
self,
position: Tuple[int, int],
position: Tuple[float, float],
width: float,
height: float,
start: float,
Expand All @@ -630,7 +632,7 @@ def arc(
Parameters
----------
position : Tuple[int, int]
position : Tuple[float, float]
Position to draw arc
width : float
Width or arc
Expand Down
3 changes: 2 additions & 1 deletion examples/rank_card1.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"xp": 1240,
"next_level_xp": 5000,
"level": 5,
"percentage": 45,
"percentage": 0,
}

background = Editor(Canvas((900, 300), color="#23272A"))
Expand Down Expand Up @@ -34,6 +34,7 @@
percentage=user_data["percentage"],
fill="#3db374",
radius=20,
stroke_width=0,
)
background.text((200, 40), user_data["name"], font=poppins, color="white")

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "easy-pil"
version = "0.3.7"
version = "0.3.8"
description = "A Python library built on top of PIL to easily edit/modify images"
keywords = ["easy-pil", "easy pillow", "Pillow", "image editing"]
authors = ["Md Shahriyar Alam <[email protected]>"]
Expand Down

0 comments on commit cee1204

Please sign in to comment.