Skip to main content

A Python Library to Generate Dynamic Share Images. Powered by Cloudinary.

Project description

ShareImage

A Python Library to Generate Dynamic Share Images. Powered by Cloudinary

Installation

Windows

pip install ShareImage

Linux / macOS

python3 -m pip install ShareImage

Usage

ShareImage Can be easily integrated in any Python Project. For example, in Flask:

from flask import Flask, render_template
from ShareImage import ShareImage

app = Flask(__name__)

@app.route('/')
def index():
    image = ShareImage(
        title="Home",
        cloudName="CLOUDINARY_CLOUD_NAME",
        imagePublicId="CLOUDINARY_IMAGE_ID"
    )
    return render_template('index.html', image=image)

@app.route('/posts/<string:slug>')
def posts(slug):
    image = ShareImage(
        title=bySlug.get(slug)['title'],
        cloudName="CLOUDINARY_CLOUD_NAME",
        imagePublicId="CLOUDINARY_IMAGE_ID"
    )
    return render_template('index.html', image=image)

if __name__=="__main__":
    app.run()

Now, you can use the image variable in any img Tag or og:image/twitter:image/image Meta Tags! Note: CLOUDINARY_CLOUD_NAME and CLOUDINARY_IMAGE_ID are respectedly Your Cloudinary Cloud Name and Image Public Id (Including Folder Name) & the bySlug is a Special Variable to find specific posts in a Array of Dictionaries by Slug and it can be achieved by the following Code:

def build_dict(seq, key):
    return dict((d[key], dict(d, index=index)) for (index, d) in enumerate(seq))

bySlug = build_dict(ARRAY_OF_POSTS, key="KEY_OF_SLUG")

# Usage: bySlug(SLUG_OF_POST)['KEY_TO_FIND']

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PIPWeb-1.0.0.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

PIPWeb-1.0.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

File details

Details for the file PIPWeb-1.0.0.tar.gz.

File metadata

  • Download URL: PIPWeb-1.0.0.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for PIPWeb-1.0.0.tar.gz
Algorithm Hash digest
SHA256 c156618c962a5bc08250ede229be27d96cb512193ea723b3ee9ac87fc7276815
MD5 d3c5e423b24cc7b485befad82c9f10db
BLAKE2b-256 1b8ded3ae4e6ad53de5dbcba9ef4c56a32a1100ab8c55a32e86b870732834d73

See more details on using hashes here.

File details

Details for the file PIPWeb-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: PIPWeb-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.1 CPython/3.9.6

File hashes

Hashes for PIPWeb-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2d232aa3eb8f609624bdd2aa5157b89aadff85f8a9d038b51dc443b2ad7c3156
MD5 ad7e180d9f2bd0eb2f80d3d465b944b5
BLAKE2b-256 2df4c6b1fc42505879b59d9d816ccb3bc7350e791abfffd93391224f89f6cd3a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page