Skip to main content

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

Project description

transimage - image format conversion

Description

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

send your PR based god🙏🏻

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 src/____main____.py ./input_image.jpg ./output_image.png png

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

Once you've cloned the repository or downloaded the source code, you can use the __main__.py file directly by using the following: python __main__.py <input_path> <output_path> <output_format>

Input target may be a single file or directory.

  • <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)

Using the transimage package in your own projects

You may test the transimage package is properly installed by running it directly from the command line: python -m transimage <input_path> <output_path> <output_format>

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

    pdm install

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

from transimage 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 transimage 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.

Contributing

Like I said, send your PR. Based. God.

Set up

  1. Install the developer dependencies: pdm install -G dev
  2. Add your changes
  3. Test your code(pdm run pytest tests/)
  4. Iterate, repeat until finished.
  5. Run the all script to lint and format the code: pdm run all

Version

1.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

transimage-1.0.0.tar.gz (7.3 kB view details)

Uploaded Source

Built Distribution

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

transimage-1.0.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: transimage-1.0.0.tar.gz
  • Upload date:
  • Size: 7.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.4 CPython/3.13.1 Windows/11

File hashes

Hashes for transimage-1.0.0.tar.gz
Algorithm Hash digest
SHA256 f04352aafa0404958c34c797f258f33eb4f42323d38b167ab6e3b46d6c7c9875
MD5 b4a5c66dd5ce91c17912befbd62f46cd
BLAKE2b-256 dd976e2b0117d6d5d8ac5a9fe91f022d8abc3f40e06b3ed7634d5245358daeaf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: transimage-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.25.4 CPython/3.13.1 Windows/11

File hashes

Hashes for transimage-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4aa0f95b930112f0e51e6664c8f6de79c4205505f9bf7c06d0b9407f109db940
MD5 642aa602d380df7d5cefc0085fc9a976
BLAKE2b-256 ddac0d4e5d69b098ef4f589fb6f7e3bfcfca40b01d81163301c60edb22b185d7

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