Skip to content

Commit

Permalink
Updated to Version 0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
NotCookey committed Jan 28, 2023
1 parent 3348049 commit 6205e42
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 18 deletions.
46 changes: 41 additions & 5 deletions Quote2Image.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: Quote2Image
Version: 0.0.4
Version: 0.0.5
Summary: A python module to convert text quotes into graphical images
Home-page: https://github.com/NotCookey/Quote2Image
Author: NotCookey
Expand All @@ -26,18 +26,23 @@ pip install Quote2Image
```

## Usage
**The convert function takes the following arguments:**
**The `Convert` function takes the following arguments:**

- **`quote` : The quote to convert.**
- **`author` : The author of the quote.**
- **`fg` : The foreground color of the text.**
- **`bg` : The background color of the image.**
- **`font_type` : The font to use for the text.**
- **`font_size` : The font size to use for the text.**
- **`font_size` : This font size is used for the quote and watermark.**
- **`font_size_author` : This font size is used for the author (Optional, Default value is set to `font_size`).**
- **`width` : The width of the image.**
- **`height` : The height of the image.**
- **`watermark_text` : The text for the watermark (Leave it blank for no watermarks).**
- **`watermark_font_size` : The font size for the watermark text (Optional, Default save is set to `font_size`).**

**Generating an image using RGB background and foreground, The package comes with a builtin `GenerateColors` function that generates a fg and bg color with the correct amount of luminosity and returns them in tuples.**
## Generating an image using RGB background and foreground

**The package comes with a builtin `GenerateColors` function that generates a fg and bg color with the correct amount of luminosity and returns them in tuples.**

```python
from Quote2Image import Convert, GenerateColors
Expand All @@ -58,7 +63,9 @@ img=Convert(
# Save The Image as a Png file
img.save("hello.png")
```
**Generating an image using a custom background image. We can do that using the `ImgObject` that gives us alot of flexibility on how we want our background Image to be.**
## Generating an image using a custom background image.

**We can do that using the `ImgObject` that gives us alot of flexibility on how we want our background Image to be.**

**The `ImgObject` class takes the following arguments:**

Expand Down Expand Up @@ -87,6 +94,35 @@ img=Convert(
img.save("hello.png")
```

## Adding a watermark:

- **`watermark_text` : The text for the watermark.**
- **`watermark_font_size` : The font size for the watermark text.**

```py
from Quote2Image import Convert, GenerateColors

# Generate Fg and Bg Color
fg, bg = GenerateColors()

img=Convert(
quote="Pooing keeps you healthy",
author="Pee",
fg=fg,
bg=bg,
font_size=32,
font_type="arial.ttf",
font_size_author=25,
width=1080,
height=450,
watermark_text="@My.Watermark",
watermark_font_size=15
)

# Save The Image as a Png file
img.save("hello.png")
```

## Permissions

- **You are allowed to use, modify, and distribute the module.**
Expand Down
19 changes: 16 additions & 3 deletions Quote2Image/Quote2Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def GenerateColors():
return foreground_color, background_color


def Convert(quote, author, fg, bg, font_type, font_size, width, height):
def Convert(quote, author, fg, bg, font_type, font_size, width, height, watermark_text, watermark_font_size:int=None, font_size_author:int=None):
if isinstance(bg, ImgObject):
image = Image.open(bg.image).resize((width, height))
enhancer = ImageEnhance.Brightness(image)
Expand All @@ -47,7 +47,11 @@ def Convert(quote, author, fg, bg, font_type, font_size, width, height):

draw = ImageDraw.Draw(image)

if font_size_author is None:
font_size_author = font_size

font = ImageFont.truetype(font_type, font_size)
font_author = ImageFont.truetype(font_type, font_size_author)

lines = []
line = ""
Expand Down Expand Up @@ -75,8 +79,17 @@ def Convert(quote, author, fg, bg, font_type, font_size, width, height):
draw.text((x, y), " - ", fg, font=font)
y += font_size // 2

author_width = draw.textsize(author, font)[0]
author_width = draw.textsize(author, font_author)[0]
x = (width - author_width) // 2
draw.text((x, y+15), author, fg, font=font)
draw.text((x, y+15), author, fg, font=font_author)

if watermark_text:
if watermark_font_size is None:
watermark_font_size = font_size
watermark_font = ImageFont.truetype(font_type, watermark_font_size)
watermark_width, watermark_height = draw.textsize(watermark_text, watermark_font)
x = width - watermark_width - 10
y = height - watermark_height - 10
draw.text((x, y), watermark_text, fg, font=watermark_font)

return image
2 changes: 1 addition & 1 deletion Quote2Image/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .Quote2Image import ImgObject
from .Quote2Image import GenerateColors
from .Quote2Image import Convert
from .Quote2Image import Convert
44 changes: 40 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ pip install Quote2Image
```

## Usage
**The convert function takes the following arguments:**
**The `Convert` function takes the following arguments:**

- **`quote` : The quote to convert.**
- **`author` : The author of the quote.**
- **`fg` : The foreground color of the text.**
- **`bg` : The background color of the image.**
- **`font_type` : The font to use for the text.**
- **`font_size` : The font size to use for the text.**
- **`font_size` : This font size is used for the quote and watermark.**
- **`font_size_author` : This font size is used for the author (Optional, Default value is set to `font_size`).**
- **`width` : The width of the image.**
- **`height` : The height of the image.**
- **`watermark_text` : The text for the watermark (Leave it blank for no watermarks).**
- **`watermark_font_size` : The font size for the watermark text (Optional, Default save is set to `font_size`).**

**Generating an image using RGB background and foreground, The package comes with a builtin `GenerateColors` function that generates a fg and bg color with the correct amount of luminosity and returns them in tuples.**
## Generating an image using RGB background and foreground

**The package comes with a builtin `GenerateColors` function that generates a fg and bg color with the correct amount of luminosity and returns them in tuples.**

```python
from Quote2Image import Convert, GenerateColors
Expand All @@ -41,7 +46,9 @@ img=Convert(
# Save The Image as a Png file
img.save("hello.png")
```
**Generating an image using a custom background image. We can do that using the `ImgObject` that gives us alot of flexibility on how we want our background Image to be.**
## Generating an image using a custom background image.

**We can do that using the `ImgObject` that gives us alot of flexibility on how we want our background Image to be.**

**The `ImgObject` class takes the following arguments:**

Expand Down Expand Up @@ -70,6 +77,35 @@ img=Convert(
img.save("hello.png")
```

## Adding a watermark:

- **`watermark_text` : The text for the watermark.**
- **`watermark_font_size` : The font size for the watermark text.**

```py
from Quote2Image import Convert, GenerateColors

# Generate Fg and Bg Color
fg, bg = GenerateColors()

img=Convert(
quote="Pooing keeps you healthy",
author="Pee",
fg=fg,
bg=bg,
font_size=32,
font_type="arial.ttf",
font_size_author=25,
width=1080,
height=450,
watermark_text="@My.Watermark",
watermark_font_size=15
)

# Save The Image as a Png file
img.save("hello.png")
```

## Permissions

- **You are allowed to use, modify, and distribute the module.**
Expand Down
19 changes: 16 additions & 3 deletions build/lib/Quote2Image/Quote2Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def GenerateColors():
return foreground_color, background_color


def Convert(quote, author, fg, bg, font_type, font_size, width, height):
def Convert(quote, author, fg, bg, font_type, font_size, width, height, watermark_text, watermark_font_size:int=None, font_size_author:int=None):
if isinstance(bg, ImgObject):
image = Image.open(bg.image).resize((width, height))
enhancer = ImageEnhance.Brightness(image)
Expand All @@ -47,7 +47,11 @@ def Convert(quote, author, fg, bg, font_type, font_size, width, height):

draw = ImageDraw.Draw(image)

if font_size_author is None:
font_size_author = font_size

font = ImageFont.truetype(font_type, font_size)
font_author = ImageFont.truetype(font_type, font_size_author)

lines = []
line = ""
Expand Down Expand Up @@ -75,8 +79,17 @@ def Convert(quote, author, fg, bg, font_type, font_size, width, height):
draw.text((x, y), " - ", fg, font=font)
y += font_size // 2

author_width = draw.textsize(author, font)[0]
author_width = draw.textsize(author, font_author)[0]
x = (width - author_width) // 2
draw.text((x, y+15), author, fg, font=font)
draw.text((x, y+15), author, fg, font=font_author)

if watermark_text:
if watermark_font_size is None:
watermark_font_size = font_size
watermark_font = ImageFont.truetype(font_type, watermark_font_size)
watermark_width, watermark_height = draw.textsize(watermark_text, watermark_font)
x = width - watermark_width - 10
y = height - watermark_height - 10
draw.text((x, y), watermark_text, fg, font=watermark_font)

return image
2 changes: 1 addition & 1 deletion build/lib/Quote2Image/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from .Quote2Image import ImgObject
from .Quote2Image import GenerateColors
from .Quote2Image import Convert
from .Quote2Image import Convert
Binary file removed dist/Quote2Image-0.0.4.tar.gz
Binary file not shown.
Binary file removed dist/Quote2Image-0.0.4.win-amd64.zip
Binary file not shown.
Binary file not shown.
Binary file added dist/Quote2Image-0.0.5.tar.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
with codecs.open(os.path.join(here, "README.md"), encoding="utf-8") as fh:
long_description = "\n" + fh.read()

VERSION = "0.0.4"
VERSION = "0.0.5"
DESCRIPTION = "A python module to convert text quotes into graphical images"
LONG_DESCRIPTION = DESCRIPTION

Expand Down

0 comments on commit 6205e42

Please sign in to comment.