gquote

Generate Beautiful quote images


Keywords
quotes, png, images, pillow, generate
License
GPL-3.0
Install
pip install gquote==3.0.0

Documentation

Gquote

Using zen.io api this libary is able to generate Quote images
using pillow, Detects quote length and adjust text size accordingly.

example

Install

Use pip to install pip install gquote

Depends on:

  • pillow
  • textwrap
  • requests

Install using pip: pip install pillow textwrap requests

Usage

This libary was designed to be as customizable as possible

Use proxy

pass requests proxy format "protocol" : "address"

from gquote import gquote

image = gquote(proxy={"https":"127.0.0.1:8080"}).run()

Custom Background with Text Shadow

You can use custom background, Optionally pass Color from your background
It will be used as text shadow, So text can be easily read,
Also it will be used to calc background Intensty,
Results in Text color From a contrast equation
Note that Custom Backround Sizes allowed: 1080x1920, 1080x1350
Color Format allowed: HEX, RGB

from gquote import gquote

image = gquote(background="/home/xd/wqfdir.jpg", color="#ff00dd").run()

Or

from urllib.request import urlretrieve
from gquote import gquote

background = urlretrieve('https://i.imgur.com/7pfR6Ua.png')[0]
image = gquote(background=background, color=(0,0,0)).run()

Change image shape/size

You can choose between two shapes portrait, or box size

from gquote import gquote

image = gquote(shape="box").run() # outputs 1080x1350

Or

from gquote import gquote

image = gquote(shape="portrait").run() # outputs 1080x1920

Change output path or format

Pass output format as name + .png, .jpg, .jpeg
Check pillow supported image formats for more

from gquote import gquote

image = gquote(output="/home/xd/cloud/quote.jpg").run()

Export to Memory

For faster output or Saving disk IO usage,
you can save to Memory as BytesIO object
Optionally you can choose output format
by passing format var, default format is PNG,
Later you can save image to disk by getbuffer(),
Make sure you use same format of the output

from gquote import gquote

image = gquote(output=False, format="jpg").run()

with open('quote.jpg', 'wb') as f: # .jpg same format
    f.write(image.getbuffer())
    f.close()

Use diffrent API

You can change the api to your choice,
also you can pass headers if api requires Auth.

from gquote import gquote

image = gquote(base="https://yourapiofchoice.io/api/quote", headers={'Content-Type': 'application/json', 'Accept': '*/*', 'Origin': 'https://zenquotes.io', 'User-Agent':....}).run()

Custom Fonts

You can pass fonts path of your choice,
ttf and otf formats are supported,
Check pillow docs for more supported formats,
You have to pass list of two fonts to be used,
one for the quote, other for the author text.

from gquote import gquote

image = gquote(fonts=["/home/xd/ubutu-font.ttf", "/home/xd/ubutu-font-italic.ttf"]).run()

Credits

Big thanks to zenquotes.io for their amazing freeware api

Donation

You can support my work by donating to the following address,

  • XMR - 433CbZXrdTBQzESkZReqQp1TKmj7MfUBXbc8FkG1jpVTBFxY9MCk1RXPWSG6CnCbqW7eiMTEGFgbHXj3rx3PxZadPgFD3DX THANKS KIND SOUL!

Find me: xd22.me