Skip to content

Commit

Permalink
Updated To Version 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
NotCookey committed Dec 29, 2022
1 parent 721c163 commit 3348049
Show file tree
Hide file tree
Showing 21 changed files with 1,075 additions and 90 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

104 changes: 104 additions & 0 deletions Quote2Image.egg-info/PKG-INFO
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
Metadata-Version: 2.1
Name: Quote2Image
Version: 0.0.4
Summary: A python module to convert text quotes into graphical images
Home-page: https://github.com/NotCookey/Quote2Image
Author: NotCookey
Author-email: kanao.nishimiya@gmail.com
Keywords: quotes,images,text,conversion,quote2image,quote to image,quote text to image
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: Unix
Classifier: License :: OSI Approved :: GNU General Public License v3 (GPLv3)
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Description-Content-Type: text/markdown
License-File: LICENSE


<h1 align="center">Quote2Image</h1>
<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>

## 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.**

**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

# 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",
width=1080,
height=450)

# 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.**

**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**
Expand Down
11 changes: 11 additions & 0 deletions Quote2Image.egg-info/SOURCES.txt
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
1 change: 1 addition & 0 deletions Quote2Image.egg-info/dependency_links.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

1 change: 1 addition & 0 deletions Quote2Image.egg-info/requires.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Pillow==9.2.0
1 change: 1 addition & 0 deletions Quote2Image.egg-info/top_level.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Quote2Image
58 changes: 0 additions & 58 deletions Quote2Image.py

This file was deleted.

82 changes: 82 additions & 0 deletions Quote2Image/Quote2Image.py
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
3 changes: 3 additions & 0 deletions Quote2Image/__init__.py
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
87 changes: 71 additions & 16 deletions README.md
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 removed __pycache__/Quote2Image.cpython-37.opt-2.pyc
Binary file not shown.
Loading

0 comments on commit 3348049

Please sign in to comment.