-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
1,075 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
LICENSE | ||
README.md | ||
setup.cfg | ||
setup.py | ||
Quote2Image/Quote2Image.py | ||
Quote2Image/__init__.py | ||
Quote2Image.egg-info/PKG-INFO | ||
Quote2Image.egg-info/SOURCES.txt | ||
Quote2Image.egg-info/dependency_links.txt | ||
Quote2Image.egg-info/requires.txt | ||
Quote2Image.egg-info/top_level.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Pillow==9.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Quote2Image |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
from PIL import Image, ImageDraw, ImageFont, ImageEnhance, ImageFilter | ||
import random | ||
|
||
|
||
class ImgObject: | ||
def __init__(self, image, brightness=100, blur=0): | ||
self.image = image | ||
self.brightness = brightness | ||
self.blur = blur | ||
|
||
def __repr__(self): | ||
return f"ImgObject(image='{self.image}', brightness={self.brightness}, blur={self.blur})" | ||
|
||
|
||
def GenerateColors(): | ||
foreground_color = ( | ||
random.randint(0, 255), | ||
random.randint(0, 255), | ||
random.randint(0, 255), | ||
) | ||
|
||
background_color = ( | ||
random.randint(0, 255), | ||
random.randint(0, 255), | ||
random.randint(0, 255), | ||
) | ||
|
||
while abs(sum(foreground_color) - sum(background_color)) < (255 * 3) / 2: | ||
background_color = ( | ||
random.randint(0, 255), | ||
random.randint(0, 255), | ||
random.randint(0, 255), | ||
) | ||
|
||
return foreground_color, background_color | ||
|
||
|
||
def Convert(quote, author, fg, bg, font_type, font_size, width, height): | ||
if isinstance(bg, ImgObject): | ||
image = Image.open(bg.image).resize((width, height)) | ||
enhancer = ImageEnhance.Brightness(image) | ||
image = enhancer.enhance(bg.brightness / 100) | ||
if bg.blur != 0: | ||
image = image.filter(ImageFilter.BoxBlur(bg.blur)) | ||
else: | ||
image = Image.new("RGB", (width, height), bg) | ||
|
||
draw = ImageDraw.Draw(image) | ||
|
||
font = ImageFont.truetype(font_type, font_size) | ||
|
||
lines = [] | ||
line = "" | ||
for word in quote.split(): | ||
line_width = draw.textsize(line + " " + word, font)[0] | ||
if line_width > width-40: | ||
lines.append(line) | ||
line = word | ||
else: | ||
line += " " + word | ||
lines.append(line) | ||
|
||
quote_height = sum([draw.textsize(line, font)[1] for line in lines]) | ||
y = (height - quote_height - font_size) // 2 | ||
|
||
for line in lines: | ||
line_width = draw.textsize(line, font)[0] | ||
x = (width - line_width) // 2 | ||
draw.text((x, y), line, fg, font=font) | ||
y += draw.textsize(line, font)[1] | ||
|
||
dash_width = draw.textsize(" - ", font)[0] | ||
x = (width - dash_width) // 2 | ||
y += font_size // 2 | ||
draw.text((x, y), " - ", fg, font=font) | ||
y += font_size // 2 | ||
|
||
author_width = draw.textsize(author, font)[0] | ||
x = (width - author_width) // 2 | ||
draw.text((x, y+15), author, fg, font=font) | ||
|
||
return image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .Quote2Image import ImgObject | ||
from .Quote2Image import GenerateColors | ||
from .Quote2Image import Convert |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,87 @@ | ||
<h1 align="center">Quote2Image</h1> | ||
<p align="center"><b>A Python Library to Make Quote Images</b></p> | ||
<p align="center"><kbd><img src="https://cdn.discordapp.com/attachments/969592495153492071/971484677045096468/unknown.png" height=300px></kbd></p> | ||
<p align="center"><b>A python module to convert text quotes into graphical images</b></p> | ||
<p align="center"><kbd><img src="https://cdn.discordapp.com/attachments/984056158149017623/1058028889588387850/hello.png" height=300px></kbd></p> | ||
|
||
# How To Use? | ||
- **Download The Latest Package From [Releases](https://github.com/SecretsX/Quote2Image/releases)** | ||
- **Extract The Zip File And Place Every File In It To Your Current Code Folder** | ||
## Installation | ||
**To install Quote2Image, you can use `pip`:** | ||
```bash | ||
pip install Quote2Image | ||
``` | ||
|
||
## Usage | ||
**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.** | ||
- **`width` : The width of the image.** | ||
- **`height` : The height of the image.** | ||
|
||
<kbd><img src="https://media.discordapp.net/attachments/905732238237368351/919182699686662204/unknown.png"></kbd> | ||
**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.** | ||
|
||
- **Code Instructions** | ||
```python | ||
from Quote2Image import convert | ||
from Quote2Image import Convert, GenerateColors | ||
|
||
# Font Size Default to 32, Height and Width by default is 612 | ||
img=convert( | ||
# Generate Fg and Bg Color | ||
fg, bg = GenerateColors() | ||
|
||
img=Convert( | ||
quote="Pooing keeps you healthy", | ||
author="Pee", | ||
fg="white", | ||
image="background_img.jpg", | ||
border_color="black", | ||
fg=fg, | ||
bg=bg, | ||
font_size=32, | ||
font_file=None, | ||
font_type="arial.ttf", | ||
width=1080, | ||
height=450) | ||
|
||
# Save The Image as a Png file | ||
img.save("quote.png") | ||
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.** | ||
|
||
**The `ImgObject` class takes the following arguments:** | ||
|
||
- **`image` : The link to the background image (required).** | ||
- **`brightness` : The brightness of the image (optional, default is 100).** | ||
- **`blur` : The blur of the image (optional, default is 0).** | ||
|
||
**You can then use the `ImgObject` instance as the bg argument in the convert function:** | ||
|
||
```py | ||
from Quote2Image import Convert, ImgObject | ||
|
||
bg=ImgObject(image="IMAGE FILE LOCATION", brightness=80, blur=80) | ||
|
||
img=Convert( | ||
quote="Pooing keeps you healthy", | ||
author="Pee", | ||
fg=(21, 21, 21), | ||
bg=bg, | ||
font_size=32, | ||
font_type="arial.ttf", | ||
width=1080, | ||
height=450) | ||
|
||
# Save The Image as a Png file | ||
img.save("hello.png") | ||
``` | ||
|
||
## Permissions | ||
|
||
- **You are allowed to use, modify, and distribute the module.** | ||
- **You are allowed to distribute modified versions of the module, as long as you follow the terms of the license.** | ||
|
||
## Obligations | ||
|
||
- **You must include a copy of the GPL-3.0 license with the module.** | ||
- **You must provide a copy of the source code of the module, either along with the modified version of the module or through a written offer to provide the source code.** | ||
- **You must provide a prominent notice stating that you have modified the module, and the date of the modification.** | ||
- **If you distribute the module, you must do so under the terms of the GPL-3.0 license.** | ||
|
||
|
||
# That's It! | ||
> Thank You! Hope this was useful to you <3 | ||
> **Thank You! Hope this was useful to you <3** |
Binary file not shown.
Oops, something went wrong.