Skip to main content

A simple image converter for Python.

Project description

banner.png

PY-SIC

GitHub release (latest by date including pre-releases) GitHub All Releases Codacy Badge GitHub

English | 简体中文

PY-SIC stands for "a simple image converter for Python". It could be seen as a simple wrapper of the popular Python imaging library Pillow, but contains a patch for better GIF conversion quality, thanks to the workaround provided by @egocarib. The idea of maintaining this repository comes from the process of refactoring the scripts in another repository of mine named Weibo Emoji. The primary purpose is automation, as I found it time-consuming to convert images and keep the original file structure manually. In summary, PY-SIC can mainly help you with:

  • Conversion tasks with an image or multiple images for many popular image formats (TODO: currently supports GIF and PNG in the alpha release)
  • Customisation including but not limited to controlling the alpha threshold for converting images to GIF ones, showing the progress bar, keeping the file structure of the input directory, and specifying the output directory.

Please note that the code is licensed under the GPL-3.0 License.

❗ ATTENTION

May I have your attention pls? 🔥

  1. By 17 October 2021, everything looks good with PyCharm 2021.2.2 + Python 3.10.0. You could definitely use Visual Studio Code, but you might need to adjust the importing behaviour in some scripts to make them run correctly.

  2. PY-SIC should support Python 3.6+, and relies on the packages listed below. To build the package yourself, please refer to the package requirements for this project.

    Name Version
    Pillow ≥ 8.4.0
    tqdm ≥ 4.62.2

📜 Docs

TODO: This part will have significant changes since PY-SIC is in its super alpha release.

Installation

pip install py-sic  # Use pip3 if required.

Sample Usage

from pysic.engine import SIC
from pysic.errors import EmptyInputError
from pysic.pillow_gif_patch import ALPHA_THRESHOLD

FAIL = "Fail:"
sic = SIC(
    has_pbar=True,  # A flag indicating whether to show the progress bar or not.
    input_path="your/path/to/input"  # The path to an input image or the directory for locating the input image(s).
)

try:
    sic.convert(
        alpha_threshold=ALPHA_THRESHOLD,  # The threshold for the alpha channel.
        has_init_output=False,  # A flag indicating if the output directory should be cleaned up first.
        has_input_structure=True,  # A flag indicating if the file structure of the input directory should be kept.
        output_dir="your/path/to/output"  # The output directory for the converted image(s).
        to_fmt=to_fmt  # The target image format for conversion.
    )
except EmptyInputError as empty_input:
    print(FAIL, empty_input)
except FileExistsError as file_exists:
    print(FAIL, file_exists)
except FileNotFoundError as input_not_found:
    print(FAIL, input_not_found)
except ValueError as value:
    print(FAIL, value)

Hope you would find it useful! 💖

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

py-sic-0.3.0a1.tar.gz (20.9 kB view details)

Uploaded Source

Built Distribution

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

py_sic-0.3.0a1-py3-none-any.whl (22.1 kB view details)

Uploaded Python 3

File details

Details for the file py-sic-0.3.0a1.tar.gz.

File metadata

  • Download URL: py-sic-0.3.0a1.tar.gz
  • Upload date:
  • Size: 20.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for py-sic-0.3.0a1.tar.gz
Algorithm Hash digest
SHA256 3474739037a94c5da221db6dc34c8c73314d32819be90afb4e40a111e32ead59
MD5 fbfda6039b45a2f58a9e08cbb81fd052
BLAKE2b-256 dec9090ff67747fc59e866fb105bce764ce4f5ad587db2288dbabc7ca86c39dc

See more details on using hashes here.

File details

Details for the file py_sic-0.3.0a1-py3-none-any.whl.

File metadata

  • Download URL: py_sic-0.3.0a1-py3-none-any.whl
  • Upload date:
  • Size: 22.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.10.0

File hashes

Hashes for py_sic-0.3.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 efa5690c91e52497db4cfc7c656a68c4c40d8490696ccde1cc9f6ad5854cdfe2
MD5 74c22930511bee96ecd78588e74e317c
BLAKE2b-256 21254ef6f9920018060aba784c51f9e89a18bd4e3483a7e0a8d2db7c4b32724a

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