Skip to main content

Converts images from one format to another using Pillow. Currently supports JPG, PNG, BMP, and WebP.

This project has been archived.

The maintainers of this project have marked this project as archived. No new releases are expected.

Project description

Pillow Image-Format Converter

Description

pil_image_converter is a Python package for converting images between different formats using the Pillow library. It supports conversions between JPG, PNG, BMP, and WebP formats.

Contributions always welcome!

Features

  • Convert images between JPG, PNG, BMP, and WebP formats
  • Batch conversion of multiple images
  • Simple command-line interface
  • Skips conversion if the input and output formats are the same

Usage

Dependencies

  • Pillow >= 11.0.0

Setup

To set up the development environment:

  1. Clone the repository
  2. Install PDM if you haven't already: pip install pdm
  3. Install dependencies: pdm install
  4. Convert images: python main.py ./input_image.jpg ./output_image.png png

Using main.py directly as a CLI tool (Recommended)

If you've cloned the repository or downloaded the source code, you can use the main.py file directly:

  1. Navigate to the directory containing main.py
  2. Run the following command:

python main.py <input_path> <output_path> <output_format>

Example:

python main.py ./input_image.jpg ./output_image.png png

For batch conversion:

python main.py ./input_directory ./output_directory png

Note: You should use quotations for paths containing spaces. -> Ex.: python main.py "./input directory" "./output directory" jpg

Using the pil_image_converter package

You can use the pil_image_converter package directly from the command line:

python -m pil_image_converter <input_path> <output_path> <output_format>

  • <input_path>: Path to the input image file or directory
  • <output_path>: Path to save the converted image(s)
  • <output_format>: Desired output format (jpg, png, bmp, or webp)

Example:

python -m pil_image_converter ./input_image.jpg ./output_image.png png

For batch conversion, provide a directory as the input path:

python -m pil_image_converter ./input_directory ./output_directory png

Using pil_image_converter in your own projects

  1. First, ensure you're working within a virtual environment with PDM:

    pdm install

  2. In your Python script, import the necessary functions:

from pil_image_converter import collect_images, ImageConverter

To convert a single image, use the ImageConverter class directly:

converter = ImageConverter('path/to/input/image.jpg', 'path/to/output/image.png', 'png')
converter.convert()

For batch conversion, you can pass in directories as arguments instead of individual image paths. Then, use the collect_images function and loop through the results:

from pil_image_converter import collect_images, ImageConverter

input_directory = 'path/to/input/directory'
output_directory = 'path/to/output/directory'
output_format = 'png'

image_files = collect_images(input_directory)

for input_path in image_files:
    filename = os.path.basename(input_path)
    name, _ = os.path.splitext(filename)
    output_path = os.path.join(output_directory, f"{name}.{output_format}")
    convert_image(input_path, output_path, output_format)

License

This project is licensed under the MIT License. See the LICENSE file for details.

Version

3.0.0

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

pil_image_converter-3.0.2.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

pil_image_converter-3.0.2-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file pil_image_converter-3.0.2.tar.gz.

File metadata

  • Download URL: pil_image_converter-3.0.2.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.22.3 CPython/3.10.11 Windows/10

File hashes

Hashes for pil_image_converter-3.0.2.tar.gz
Algorithm Hash digest
SHA256 b74f135b13719e5910f070e84710257557a1007f7cb8d4813cf1d2809bd5e984
MD5 49486e6c6b59199df318eaa1ac31e1f1
BLAKE2b-256 40ca604d4970152f203ef9e19912da047bd42ecbfd957d838f1d99e3b1792c8a

See more details on using hashes here.

File details

Details for the file pil_image_converter-3.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for pil_image_converter-3.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a49d0c3649e7205619957a473ef369b1fc0d5f0e7a72ff7243bb5d843e588a30
MD5 9b56db7e467a55ff649795e468ccacce
BLAKE2b-256 4bca5972d42b914ef1d78e717ebc6e04166d9d7e42909f86b7e317f27f3f4a90

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