Skip to main content

Small package that optimizes images for the web.

Project description

PyPI PyPI - Downloads

web-mage

web-mage is a simple Python package that's used to automate the process of optimizing image files for the web. It can be imported and customized in a Python module, or run simply as a command-line utility.

This project is functional, but still in early development.

Installation

Install using pip:

pip install web-mage

Usage

python3 -m web_mage SOURCE_DIR DEST_DIR

This will optimize all files in SOURCE_DIR to 60% quality with no image resizing, and output them to DEST_DIR with a filename suffix.

Usage in Code

This is the preferred method of usage. You can import web-mage into Python if you want to run jobs in a script or program, or customize the way images are optimized.

from web_mage.web_mage import Job
from web_mage.formats import IMG_FORMAT_CONTENT_LARGE

formats = [IMG_FORMAT_CONTENT_LARGE]
optim_job = Job(source="/path/to/source/directory",
                dest="/path/to/output/directory",
                formats=formats)
optim_job.run()

You can use multiple formats if you want images to be optimized for multiple different devices or layouts. You can also define your own image formats based on a few different parameters.

from web_mage.formats import (ImageFormat,
                              IMG_FORMAT_CONTENT_LARGE,
                              IMG_FORMAT_CONTENT_MEDIUM,
                              IMG_FORMAT_CONTENT_SMALL)

my_format = ImageFormat(max_width=1024,  # Image will be resized based on dimensions.
                        max_height=768,
                        min_quality=85,  # This will optimize to 85% quality.
                        tag="my_format") # Tags are appended to the filename of the
                                         # resulting file so multiple output formats
                                         # can be distinguished.
my_other_format = ImageFormat(max_dimension=1280, # This will ensure that neither height
                                                  # nor width will exceed 1280 pixels.
                              tag="my_other_format")

formats = [IMG_FORMAT_CONTENT_LARGE,
           IMG_FORMAT_CONTENT_MEDIUM,
           IMG_FORMAT_CONTENT_SMALL,
           my_format,
           my_other_format]

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

web_mage-0.2.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

web_mage-0.2.0-py2.py3-none-any.whl (5.7 kB view details)

Uploaded Python 2Python 3

File details

Details for the file web_mage-0.2.0.tar.gz.

File metadata

  • Download URL: web_mage-0.2.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.5.2

File hashes

Hashes for web_mage-0.2.0.tar.gz
Algorithm Hash digest
SHA256 8088676a9d4f6c65e5e110f89cabe9b06c7e9fbfda142a84101d63ad43f74af3
MD5 cfd875f12c3db06324319bcd89a39f94
BLAKE2b-256 26d3d97a89415a8949009bd4406c7a281740c6c203a74bc270866f637be98e31

See more details on using hashes here.

File details

Details for the file web_mage-0.2.0-py2.py3-none-any.whl.

File metadata

  • Download URL: web_mage-0.2.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.5.2

File hashes

Hashes for web_mage-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 3a95d2e80d8354cf64160fd5b63c6823ea0d343b3cdadab952bf1d0c78e0b1d0
MD5 ca8382df960e47f0740cac3be3336a79
BLAKE2b-256 29e1b1a04df8e979a8dde80b62e5e74a432266712829c182ec6817e2f0c76a6c

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