pyimager package

Submodules

pyimager.pyimager module

pyimager.pyimager.circropper(input_path, margin, output_path=None)

Crops an image into a circle and leave some margin as you defined

Parameters:
  • input_path (string) – The file path of the image to be cropped
  • margin (float or int) – The distance between circle boundary and the original image boundary
  • output_path (string) – The path to the output image
Returns:

Return type:

A new cropped Image object

Examples

>>> from pyimager import pyimager
>>> circropper('images/mandrill.jpg', 0, 'images/mandrill_circropper.png')
pyimager.pyimager.imgfilter(input_path, filter_type, strength, output_path=None)

Applies a filter to a given image to edit the visual aesthetic.

The filter types include ‘blur’ and ‘sharpen’; where blur blends neighboring pixels and sharpen enhances edges. The strength of the filter indicates how much of effect is apllied to the image; where 0 is no effect and 1 is very strong effect.

Parameters:
  • input_path (str) – path to the input image
  • filter_type (str) – filter to be applied to the input image options: ‘blur’, ‘sharpen’
  • strength (int or float (0 to 1)) – the strength of the selected filter effect
  • output_path (str or None (default = None)) – path to the modified output image file; if None, the image will not be saved to a file
Returns:

Array of pixels which comprises the original image with the applied filter

Return type:

np.array

Examples

>>> from pyimager import pyimager
>>> pyimager.imgfilter("images/mandrill.jpg", "blur", 0.4)
# An array of pixels resulting in an image with a
# moderate blurred effect.
pyimager.pyimager.reducolor(input_path, style, output_path=None)

Reduce image colors to have the cartoonized effect

Parameters:
  • input_path (string) – The file path of the image
  • style (list,) – either two colors from [‘white’, ‘black’, ‘red’, ‘green’, ‘blue’, ‘yellow’, ‘pink’, ‘aqua’] or [‘eight’] for eight colors
  • output_path (string or None(default)) – if None, the modified image will not be saved if ‘auto’, the modified image will be saved in the same folder as the image or the modified image will be saved in the provided folder path
Returns:

  • numpy.ndarray
  • the altered image and the image is saved in the designated path if output_path is not None

Examples

>>> from pyimager import pyimager
>>> pyimager.reducolor('tests/mandrill.jpg', ['eight'], 'auto')
>>> pyimager.reducolor('tests/mandrill.jpg', ['white', 'black'], 'auto')
pyimager.pyimager.redusize(input_path, output_path, new_height, new_width)

A function to reduce the dimension of a given image by removing vertical and horizontal seams

Parameters:
  • input_path (str) – path to the input image
  • output_path (str) – path to the output image
  • new_width (int) – new width the output image
  • new_height (int) – new height of the output image
Returns:

Return type:

A new image with new width and height

Examples

>>> from pyimager import pyimager
>>> pyimager.redusize("bear.jpg", "result.png", 33, 33)
# A file named "result.png" with the width 33 and height 33 will be
# generated in the current folder.

Module contents