Skip to content

Commit 3348049

Browse files
committed
Updated To Version 0.0.4
1 parent 721c163 commit 3348049

21 files changed

+1075
-90
lines changed

LICENSE

+674
Large diffs are not rendered by default.

Quote2Image.egg-info/PKG-INFO

+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
Metadata-Version: 2.1
2+
Name: Quote2Image
3+
Version: 0.0.4
4+
Summary: A python module to convert text quotes into graphical images
5+
Home-page: https://github.com/NotCookey/Quote2Image
6+
Author: NotCookey
7+
Author-email: kanao.nishimiya@gmail.com
8+
Keywords: quotes,images,text,conversion,quote2image,quote to image,quote text to image
9+
Classifier: Programming Language :: Python :: 3
10+
Classifier: Operating System :: Unix
11+
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
12+
Classifier: Operating System :: MacOS :: MacOS X
13+
Classifier: Operating System :: Microsoft :: Windows
14+
Description-Content-Type: text/markdown
15+
License-File: LICENSE
16+
17+
18+
<h1 align="center">Quote2Image</h1>
19+
<p align="center"><b>A python module to convert text quotes into graphical images</b></p>
20+
<p align="center"><kbd><img src="https://cdn.discordapp.com/attachments/984056158149017623/1058028889588387850/hello.png" height=300px></kbd></p>
21+
22+
## Installation
23+
**To install Quote2Image, you can use `pip`:**
24+
```bash
25+
pip install Quote2Image
26+
```
27+
28+
## Usage
29+
**The convert function takes the following arguments:**
30+
31+
- **`quote` : The quote to convert.**
32+
- **`author` : The author of the quote.**
33+
- **`fg` : The foreground color of the text.**
34+
- **`bg` : The background color of the image.**
35+
- **`font_type` : The font to use for the text.**
36+
- **`font_size` : The font size to use for the text.**
37+
- **`width` : The width of the image.**
38+
- **`height` : The height of the image.**
39+
40+
**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.**
41+
42+
```python
43+
from Quote2Image import Convert, GenerateColors
44+
45+
# Generate Fg and Bg Color
46+
fg, bg = GenerateColors()
47+
48+
img=Convert(
49+
quote="Pooing keeps you healthy",
50+
author="Pee",
51+
fg=fg,
52+
bg=bg,
53+
font_size=32,
54+
font_type="arial.ttf",
55+
width=1080,
56+
height=450)
57+
58+
# Save The Image as a Png file
59+
img.save("hello.png")
60+
```
61+
**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.**
62+
63+
**The `ImgObject` class takes the following arguments:**
64+
65+
- **`image` : The link to the background image (required).**
66+
- **`brightness` : The brightness of the image (optional, default is 100).**
67+
- **`blur` : The blur of the image (optional, default is 0).**
68+
69+
**You can then use the `ImgObject` instance as the bg argument in the convert function:**
70+
71+
```py
72+
from Quote2Image import Convert, ImgObject
73+
74+
bg=ImgObject(image="IMAGE FILE LOCATION", brightness=80, blur=80)
75+
76+
img=Convert(
77+
quote="Pooing keeps you healthy",
78+
author="Pee",
79+
fg=(21, 21, 21),
80+
bg=bg,
81+
font_size=32,
82+
font_type="arial.ttf",
83+
width=1080,
84+
height=450)
85+
86+
# Save The Image as a Png file
87+
img.save("hello.png")
88+
```
89+
90+
## Permissions
91+
92+
- **You are allowed to use, modify, and distribute the module.**
93+
- **You are allowed to distribute modified versions of the module, as long as you follow the terms of the license.**
94+
95+
## Obligations
96+
97+
- **You must include a copy of the GPL-3.0 license with the module.**
98+
- **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.**
99+
- **You must provide a prominent notice stating that you have modified the module, and the date of the modification.**
100+
- **If you distribute the module, you must do so under the terms of the GPL-3.0 license.**
101+
102+
103+
# That's It!
104+
> **Thank You! Hope this was useful to you <3**

Quote2Image.egg-info/SOURCES.txt

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
LICENSE
2+
README.md
3+
setup.cfg
4+
setup.py
5+
Quote2Image/Quote2Image.py
6+
Quote2Image/__init__.py
7+
Quote2Image.egg-info/PKG-INFO
8+
Quote2Image.egg-info/SOURCES.txt
9+
Quote2Image.egg-info/dependency_links.txt
10+
Quote2Image.egg-info/requires.txt
11+
Quote2Image.egg-info/top_level.txt
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

Quote2Image.egg-info/requires.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Pillow==9.2.0

Quote2Image.egg-info/top_level.txt

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Quote2Image

Quote2Image.py

-58
This file was deleted.

Quote2Image/Quote2Image.py

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
from PIL import Image, ImageDraw, ImageFont, ImageEnhance, ImageFilter
2+
import random
3+
4+
5+
class ImgObject:
6+
def __init__(self, image, brightness=100, blur=0):
7+
self.image = image
8+
self.brightness = brightness
9+
self.blur = blur
10+
11+
def __repr__(self):
12+
return f"ImgObject(image='{self.image}', brightness={self.brightness}, blur={self.blur})"
13+
14+
15+
def GenerateColors():
16+
foreground_color = (
17+
random.randint(0, 255),
18+
random.randint(0, 255),
19+
random.randint(0, 255),
20+
)
21+
22+
background_color = (
23+
random.randint(0, 255),
24+
random.randint(0, 255),
25+
random.randint(0, 255),
26+
)
27+
28+
while abs(sum(foreground_color) - sum(background_color)) < (255 * 3) / 2:
29+
background_color = (
30+
random.randint(0, 255),
31+
random.randint(0, 255),
32+
random.randint(0, 255),
33+
)
34+
35+
return foreground_color, background_color
36+
37+
38+
def Convert(quote, author, fg, bg, font_type, font_size, width, height):
39+
if isinstance(bg, ImgObject):
40+
image = Image.open(bg.image).resize((width, height))
41+
enhancer = ImageEnhance.Brightness(image)
42+
image = enhancer.enhance(bg.brightness / 100)
43+
if bg.blur != 0:
44+
image = image.filter(ImageFilter.BoxBlur(bg.blur))
45+
else:
46+
image = Image.new("RGB", (width, height), bg)
47+
48+
draw = ImageDraw.Draw(image)
49+
50+
font = ImageFont.truetype(font_type, font_size)
51+
52+
lines = []
53+
line = ""
54+
for word in quote.split():
55+
line_width = draw.textsize(line + " " + word, font)[0]
56+
if line_width > width-40:
57+
lines.append(line)
58+
line = word
59+
else:
60+
line += " " + word
61+
lines.append(line)
62+
63+
quote_height = sum([draw.textsize(line, font)[1] for line in lines])
64+
y = (height - quote_height - font_size) // 2
65+
66+
for line in lines:
67+
line_width = draw.textsize(line, font)[0]
68+
x = (width - line_width) // 2
69+
draw.text((x, y), line, fg, font=font)
70+
y += draw.textsize(line, font)[1]
71+
72+
dash_width = draw.textsize(" - ", font)[0]
73+
x = (width - dash_width) // 2
74+
y += font_size // 2
75+
draw.text((x, y), " - ", fg, font=font)
76+
y += font_size // 2
77+
78+
author_width = draw.textsize(author, font)[0]
79+
x = (width - author_width) // 2
80+
draw.text((x, y+15), author, fg, font=font)
81+
82+
return image

Quote2Image/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .Quote2Image import ImgObject
2+
from .Quote2Image import GenerateColors
3+
from .Quote2Image import Convert

README.md

+71-16
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,87 @@
11
<h1 align="center">Quote2Image</h1>
2-
<p align="center"><b>A Python Library to Make Quote Images</b></p>
3-
<p align="center"><kbd><img src="https://cdn.discordapp.com/attachments/969592495153492071/971484677045096468/unknown.png" height=300px></kbd></p>
2+
<p align="center"><b>A python module to convert text quotes into graphical images</b></p>
3+
<p align="center"><kbd><img src="https://cdn.discordapp.com/attachments/984056158149017623/1058028889588387850/hello.png" height=300px></kbd></p>
44

5-
# How To Use?
6-
- **Download The Latest Package From [Releases](https://github.com/SecretsX/Quote2Image/releases)**
7-
- **Extract The Zip File And Place Every File In It To Your Current Code Folder**
5+
## Installation
6+
**To install Quote2Image, you can use `pip`:**
7+
```bash
8+
pip install Quote2Image
9+
```
10+
11+
## Usage
12+
**The convert function takes the following arguments:**
13+
14+
- **`quote` : The quote to convert.**
15+
- **`author` : The author of the quote.**
16+
- **`fg` : The foreground color of the text.**
17+
- **`bg` : The background color of the image.**
18+
- **`font_type` : The font to use for the text.**
19+
- **`font_size` : The font size to use for the text.**
20+
- **`width` : The width of the image.**
21+
- **`height` : The height of the image.**
822

9-
<kbd><img src="https://media.discordapp.net/attachments/905732238237368351/919182699686662204/unknown.png"></kbd>
23+
**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.**
1024

11-
- **Code Instructions**
1225
```python
13-
from Quote2Image import convert
26+
from Quote2Image import Convert, GenerateColors
1427

15-
# Font Size Default to 32, Height and Width by default is 612
16-
img=convert(
28+
# Generate Fg and Bg Color
29+
fg, bg = GenerateColors()
30+
31+
img=Convert(
1732
quote="Pooing keeps you healthy",
1833
author="Pee",
19-
fg="white",
20-
image="background_img.jpg",
21-
border_color="black",
34+
fg=fg,
35+
bg=bg,
2236
font_size=32,
23-
font_file=None,
37+
font_type="arial.ttf",
2438
width=1080,
2539
height=450)
2640

2741
# Save The Image as a Png file
28-
img.save("quote.png")
42+
img.save("hello.png")
2943
```
44+
**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.**
45+
46+
**The `ImgObject` class takes the following arguments:**
47+
48+
- **`image` : The link to the background image (required).**
49+
- **`brightness` : The brightness of the image (optional, default is 100).**
50+
- **`blur` : The blur of the image (optional, default is 0).**
51+
52+
**You can then use the `ImgObject` instance as the bg argument in the convert function:**
53+
54+
```py
55+
from Quote2Image import Convert, ImgObject
56+
57+
bg=ImgObject(image="IMAGE FILE LOCATION", brightness=80, blur=80)
58+
59+
img=Convert(
60+
quote="Pooing keeps you healthy",
61+
author="Pee",
62+
fg=(21, 21, 21),
63+
bg=bg,
64+
font_size=32,
65+
font_type="arial.ttf",
66+
width=1080,
67+
height=450)
68+
69+
# Save The Image as a Png file
70+
img.save("hello.png")
71+
```
72+
73+
## Permissions
74+
75+
- **You are allowed to use, modify, and distribute the module.**
76+
- **You are allowed to distribute modified versions of the module, as long as you follow the terms of the license.**
77+
78+
## Obligations
79+
80+
- **You must include a copy of the GPL-3.0 license with the module.**
81+
- **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.**
82+
- **You must provide a prominent notice stating that you have modified the module, and the date of the modification.**
83+
- **If you distribute the module, you must do so under the terms of the GPL-3.0 license.**
84+
3085

3186
# That's It!
32-
> Thank You! Hope this was useful to you <3
87+
> **Thank You! Hope this was useful to you <3**
-1.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)