Formaverter (Format Converter) is a Python tool that allows you to convert images between different formats using the Pillow library. It supports conversions between JPG, PNG, BMP, and WebP formats.
- 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
pip install formaverter
Apologies, I'm having trouble publishing the package.
For now, disregard instructions in this README that call for Formaverter's installation via Pip or other tools. Formaverter is not currently available on PyPI.
The easiest way to use it is by cloning this repository, installing Pillow to a virtual environment, and running the main.py
file directly.
If you've cloned the repository or downloaded the source code, you can use the main.py
file directly:
- Navigate to the directory containing
main.py
- 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: When using main.py
directly, make sure you have all the required dependencies installed in your Python environment.
You can use the Formaverter package directly from the command line:
python -m 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 image_converter ./input_image.jpg ./output_image.png png
For batch conversion, provide a directory as the input path:
python -m image_converter ./input_directory ./output_directory png
You can also import and use Formaverter in your own Python projects. Here's how:
-
First, make sure you've installed Formaverter:
pip install formaverter
-
In your Python script, import the necessary functions:
from formaverter import convert_image, ImageConverter
To convert a single image using the straightforward convert_image
function:
convert_image('path/to/input/image.jpg', 'path/to/output/image.png', 'png')
To 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 use the collect_images function and loop through the results:
from formaverter import collect_images, convert_image
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)
This allows you to integrate Formaverter's functionality into your own Python scripts or larger projects, giving you more control over the conversion process.
- Pillow >= 11.0.0
To set up the development environment:
- Clone the repository
- Install PDM if you haven't already:
pip install pdm
- Install dependencies:
pdm install
- Run tests: ex.
python -m unittest .\tests\test_image_converter.py
Contributions are welcome! Please feel free to submit a Pull Request.
This project is licensed under the GNU Affero General Public License. See the LICENSE file for details.
Daethyra [email protected]
2.0.0