Introduction

https://img.shields.io/pypi/v/imagefactory.svg https://img.shields.io/travis/jaantollander/imagefactory.svg Documentation Status Updates

Python package for creating test images. Test images can be created as in memory images or saved in to the filesystem. Package is released under MIT license.

Examples

Examples of the images created by the package.

jpeg png svg
example.jpeg example png example svg

Basic Usage

Currently there is only one function create_image.

imagefactory.imagefactory.create_image(name='untitled', filetype='png', width=48, height=48, text=None, savedir=None, overwrite=False)[source]

Creates in memory images for testing [1]. Bitmap images are created

>>> from imagefactory import create_image
>>> create_image()
<_io.BytesIO object at ...>

Vector graphic images can be created

>>> from imagefactory import create_image
>>> create_image(filetype='svg')
<_io.StringIO object at ...>
Parameters:
  • name (str) –
    • name Name of the file.
    • name.ext If extension is supplied it overwrites any supplied filetype.
  • width (int) – Positive integer
  • height (int) – Positive integer
  • filetype (str) – Filetype is extension string: jpeg, png, gif, svg
  • text (str, optional) –
    • Default: None uses {width}x{height}
    • Otherwise supplied text string is used.
  • savedir (str, optional) –
    • Default: None doesn’t save the image
    • Otherwise save image to savedir directory
  • overwrite (Boolean) – Boolean flag for toggling if existing file in the same filepath should be overwritten.
Returns:

Image as BytesIO or StringIO object. It can be used in same fashion as file object created by opening a file.

Return type:

BytesIO|StringIO

References

[1]http://wildfish.com/blog/2014/02/27/generating-in-memory-image-for-tests-python/