A tiny Python library that lets you convert an RGB image to grayscale.
The library can accept either a filename (returning the filename of the converted file), or an image that has been loaded into a StringIO object (returning a new StringIO object with the converted image):
convert_file_to_grayscale(filename)
# returns filename of the resulting grayscale file
convert_to_grayscale(string_io)
# returns a new StringIO object with the converted image
The grayscale conversion algorithm used is the luminosity method, as described in Wikipedia.
grayscalelib
supports JPG and PNG files as inputs. (It might support other
file formats, as supported by pillow
, the library used for image decoding, but it has
only been tested with JPG and PNG files. See pillow
's format documentation for details.)
grayscalelib
has only been tested with Python 2.7
To install grayscalelib
's dependencies:
$ pip install -r requirements.txt
For an example of usage, see example.py
, which you can run with:
$ python example.py testdata/test_image.jpg
For detailed documentation and implementation details, please read the docstrings in grayscalelib.py.
To run the library's tests, from the repository's root directory run:
$ python grayscalelib_test.py