Editor

class ez_pil.editor.Editor(_image)

Editor class. It does all the editing operations.

Parameters:

_image (Image | str | BytesIO | Editor | Canvas | Path) – Image or Canvas to edit.

arc(position, width, height, start, rotation, fill=None, color=None, stroke_width=1)

Draw arc.

Parameters:
  • position (tuple[float, float]) – Position to draw arc

  • width (float) – Width or arc

  • height (float) – Height of arch

  • start (float) – Start position of arch

  • rotation (float) – Rotation in degree

  • fill (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Fill color, by default None

  • color (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Alias of fill, by default None

  • stroke_width (float) – Stroke width, by default 1

Return type:

Editor

bar(position, max_width, height, percentage=1, fill=None, color=None, outline=None, stroke_width=1, radius=0)

Draw a progress bar.

Parameters:
  • position (tuple[int, int]) – Position to draw bar

  • max_width (int | float) – Max width of the bar

  • height (int | float) – Height of the bar

  • percentage (int) – Percentage to fill of the bar, by default 1

  • fill (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Fill color, by default None

  • color (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Alias of fill, by default None

  • outline (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Outline color, by default None

  • stroke_width (float) – Stroke width, by default 1

  • radius (int) – Radius of the bar, by default 0

Return type:

Editor

blend(image, alpha=0.0, on_top=False)

Blend image into editor image.

Parameters:
  • image (Image | Editor | Canvas) – Image to blend

  • alpha (float) – Alpha amount, by default 0.0

  • on_top (bool) – Places image on top, by default False

Return type:

Editor

blur(mode='gaussian', amount=1)

Blur image.

Parameters:
  • mode (Literal['box', 'gaussian']) – Blur mode, by default “gaussian”

  • amount (float) – Amount of blur, by default 1

Return type:

Editor

circle_image()

Make image circle.

Return type:

Editor

close()
ellipse(position, width, height, fill=None, color=None, outline=None, stroke_width=1)

Draw an ellipse.

Parameters:
  • position (tuple[float, float]) – Position to draw ellipse

  • width (float) – Width of ellipse

  • height (float) – Height of ellipse

  • fill (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Fill color, by default None

  • color (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Alias of fill, by default None

  • outline (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Outline color, by default None

  • stroke_width (float) – Stroke width, by default 1

Return type:

Editor

property image_bytes: BytesIO

Return image bytes.

multi_text(position, texts, space_separated=True, align='left')

Draw multicolor text.

Parameters:
  • position (tuple[float, float]) – Position to draw text

  • texts (list[Text]) – List of texts

  • space_separated (bool) – Separate texts with space, by default True

  • align (Literal['left', 'center', 'right']) – Align texts, by default “left”

Return type:

Editor

paste(image, position)

Paste image into editor.

Parameters:
  • image (Image | Editor | Canvas) – Image to paste

  • position (tuple[int, int]) – Position to paste

Return type:

Editor

polygon(coordinates, fill=None, color=None, outline=None)

Draw a polygon.

Parameters:
  • coordinates (list) – Coordinates to draw

  • fill (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Fill color, by default None

  • color (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Alias of fill, by default None

  • outline (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Outline color, by default None

Return type:

Editor

rectangle(position, width, height, fill=None, color=None, outline=None, stroke_width=1, radius=0)

Draw rectangle into image.

Parameters:
  • position (tuple[float, float]) – Position to draw rectangle

  • width (float) – Width of rectangle

  • height (float) – Height of rectangle

  • fill (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Fill color, by default None

  • color (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Alias of fill, by default None

  • outline (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Outline color, by default None

  • stroke_width (float) – Stroke width, by default 1

  • radius (int) – Radius of rectangle, by default 0

Return type:

Editor

resize(size, crop=False)

Resize image.

Parameters:
  • size (tuple[int, int]) – New Size of image

  • crop (bool) – Crop the image to bypass distortion, by default False

Return type:

Editor

rotate(deg=0, expand=False)

Rotate image.

Parameters:
  • deg (float) – Degrees to rotate, by default 0

  • expand (bool) – Expand while rotating, by default False

Return type:

Editor

rounded_bar(position, width, height, percentage, fill=None, color=None, stroke_width=1)

Draw a rounded bar.

Parameters:
  • position (tuple[float, float]) – Position to draw rounded bar

  • width (int | float) – Width of the bar

  • height (int | float) – Height of the bar

  • percentage (float) – Percentage to fill.

  • fill (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Fill color, by default None

  • color (int | str | tuple[int, int, int] | tuple[int, int, int, int] | None) – Alias of color, by default None

  • stroke_width (float) – Stroke width, by default 1

Return type:

Editor

rounded_corners(radius=10, offset=2)

Make image rounded corners.

Parameters:
  • radius (int) – Radius of roundness, by default 10

  • offset (int) – Offset pixel while making rounded, by default 2

Return type:

Editor

save(fp, file_format=None, **params)

Save the image.

Parameters:
  • fp (str) – File path

  • file_format (str | None) – File format, by default None

show()

Show the image.

text(position, text, font=None, color='black', align='left', stroke_width=None, stroke_fill='black')

Draw text into image.

Parameters:
  • position (tuple[float, float]) – Position to draw text.

  • text (str) – Text to draw

  • font (FreeTypeFont | Font | None) – Font used for text, by default None

  • color (int | str | tuple[int, int, int] | tuple[int, int, int, int]) – Color of the font, by default “black”

  • align (Literal['left', 'center', 'right']) – Align text, by default “left”

  • stroke_width (int | None) – Whether there should be any stroke. Defaults to None. It represents the width of the said stroke.

  • stroke_fill (int | str | tuple[int, int, int] | tuple[int, int, int, int]) – Color of the stroke, if any stroke is applied to the text. Defaults to “black”

Return type:

Editor