### Install easy-pil Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/pages/intro.rst Instructions for installing the easy-pil library directly from PyPI using pip. Includes commands for both general use and Windows users. ```Shell python3 -m pip install -U easy-pil ``` ```Shell py -3 -m pip install -U easy-pil ``` -------------------------------- ### Generate Welcome Image with easy-pil Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/examples/welcome_image_two.rst This snippet demonstrates how to create a welcome image by loading a background, resizing and applying a circular mask to a profile picture, and overlaying custom text with specified fonts and colors. It utilizes the Editor, Font, and Text classes from the easy_pil library. ```python from easy_pil import Editor, Font, Text background = Editor("assets/wlcbg.jpg") profile = Editor("assets/pfp.png").resize((150, 150)).circle_image() # For profile to use users profile picture load it from url using the load_image/load_image_async function # profile_image = load_image(str(ctx.author.avatar_url)) # profile = Editor(profile_image).resize((150, 150)).circle_image() # Fonts poppins = Font.poppins(size=50, variant="bold") poppins_small = Font.poppins(size=25, variant="regular") poppins_light = Font.poppins(size=20, variant="light") background.paste(profile, (325, 90)) background.ellipse((325, 90), 150, 150, outline="gold", stroke_width=4) background.text((400, 260), "WELCOME", color="white", font=poppins, align="center") background.text( (400, 325), "Shahriyar#9770", color="white", font=poppins_small, align="center" ) background.text( (400, 360), "You are the 457th Member", color="#0BE7F5", font=poppins_small, align="center", ) background.show() ``` -------------------------------- ### Basic easy-pil Usage Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/pages/intro.rst A fundamental example demonstrating how to use the easy-pil library to create a canvas, add text to it, and display the result. Requires the Editor and Canvas classes from easy_pil. ```Python from easy_pil import Editor, Canvas board = Canvas(width=500, height=500) editor = Editor(board) editor.text((10, 10), "Hello World") editor.show() # .save() to save the image ``` -------------------------------- ### Generate Welcome Image with Easy-PIL Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/examples/welcome_image.rst This snippet shows how to create a welcome image using easy-pil. It covers canvas creation, image editing (resizing, circular cropping), font loading, text rendering with custom styles, and image manipulation like polygon drawing and pasting. ```python from easy_pil import Canvas, Editor, Font, Text, font background = Editor(Canvas((900, 270), "#23272a")) profile = Editor("assets/pfp.png").resize((200, 200)).circle_image() # For profile to use users profile picture load it from url using the load_image/load_image_async function # profile_image = load_image(str(ctx.author.avatar_url)) # profile = Editor(profile_image).resize((150, 150)).circle_image() # Fonts to use with different size poppins_big = Font.poppins(variant="bold", size=50) poppins_mediam = Font.poppins(variant="bold", size=40) poppins_regular = Font.poppins(variant="regular", size=30) poppins_thin = Font.poppins(variant="light", size=18) card_left_shape = [(0, 0), (0, 270), (330, 270), (260, 0)] background.polygon(card_left_shape, "#2C2F33") background.paste(profile, (40, 35)) background.ellipse((40, 35), 200, 200, outline="white", stroke_width=3) background.text((600, 20), "WELCOME", font=poppins_big, color="white", align="center") background.text( (600, 70), "Shahriyar#9770", font=poppins_regular, color="white", align="center" ) background.text( (600, 120), "YOU ARE MEMBER", font=poppins_mediam, color="white", align="center" ) background.text( (600, 160), "GUILD 4359", font=poppins_regular, color="white", align="center" ) background.text( (620, 245), "THANK YOU FOR JOINING. HOPE YOU WILL ENJOY YOUR STAY", font=poppins_thin, color="white", align="center", ) background.show() ``` -------------------------------- ### Generate Owo Leveling Card with Easy-PIL Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/examples/owo_level.rst This snippet shows how to create a user leveling card. It involves setting up user data, loading a background and profile picture, defining fonts, and then drawing text, rectangles, and progress bars onto the canvas using Easy-PIL's Editor class. ```python from easy_pil import Canvas, Editor, Font user_data = { "name": "Shahriyar#9770", "bio": "An Example Bot user", "level": "15", "xp": "1.2k / 3k", "percentage": 45, } background = Editor(Canvas((800, 240), color="#23272A")) profile = Editor("assets/pfp.png").resize((200, 200)) # For profile to use users profile picture load it from url using the load_image/load_image_async function # profile_image = load_image(str(ctx.author.avatar_url)) # profile = Editor(profile_image).resize((200, 200)) font_40 = Font.poppins(size=40) font_20 = Font.montserrat(size=20) font_25 = Font.poppins(size=25) font_40_bold = Font.poppins(size=40, variant="bold") background.paste(profile, (20, 20)) background.text((240, 20), user_data["name"], font=font_40, color="white") background.text((240, 80), user_data["bio"], font=font_20, color="white") background.text((250, 170), "LVL", font=font_25, color="white") background.text((310, 155), user_data["level"], font=font_40_bold, color="white") background.rectangle((390, 170), 360, 25, outline="white", stroke_width=2) background.bar( (394, 174), 352, 17, percentage=user_data["percentage"], fill="white", stroke_width=2, ) background.text((390, 135), "Rank : 45", font=font_25, color="white") background.text( (750, 135), f"XP : {user_data['xp']}", font=font_25, color="white", align="right" ) background.show() ``` -------------------------------- ### Python Rank Card Generation with easy-pil Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/examples/rank_card.rst This snippet shows how to create a rank card using easy-pil. It covers initializing a canvas, loading and editing a profile picture, applying fonts, drawing custom shapes and progress bars, and adding text elements to display user information like name, level, and XP progress. ```python from easy_pil import Canvas, Editor, Font user_data = { # Most likely coming from database or calculation "name": "Shahriyar#9770", # The user's name "xp": 1240, "next_level_xp": 5000, "level": 5, "percentage": 45, } background = Editor(Canvas((900, 300), color="#23272A")) profile = Editor("assets/pfp.png").resize((150, 150)).circle_image() # For profile to use users profile picture load it from url using the load_image/load_image_async function # profile_image = load_image(str(ctx.author.avatar_url)) # profile = Editor(profile_image).resize((150, 150)).circle_image() poppins = Font.poppins(size=40) poppins_small = Font.poppins(size=30) card_right_shape = [(600, 0), (750, 300), (900, 300), (900, 0)] background.polygon(card_right_shape, "#2C2F33") background.paste(profile, (30, 30)) background.rectangle((30, 220), width=650, height=40, fill="#494b4f", radius=20) background.bar( (30, 220), max_width=650, height=40, percentage=user_data["percentage"], fill="#3db374", radius=20, ) background.text((200, 40), user_data["name"], font=poppins, color="white") background.rectangle((200, 100), width=350, height=2, fill="#17F3F6") background.text( (200, 130), f"Level : {user_data['level']} " + f" XP : {user_data['xp']} / {user_data['next_level_xp']}", font=poppins_small, color="white", ) background.show() ``` -------------------------------- ### Generate Rank Card with Easy-PIL Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/examples/rank_card_two.rst This snippet demonstrates how to create a rank card using Easy-PIL. It involves setting up a canvas, loading and editing a profile picture, drawing various elements like rectangles, ellipses, text, and a progress bar based on user data. The final card is then displayed. ```python from easy_pil import Canvas, Editor, Font, Text user_data = { # Most likely coming from database or calculation "name": "Shahriyar#9770", # The user's name "xp": "1.2k", "next_level_xp": "5k", "level": "5", "percentage": 45, "rank": 10, } background = Editor(Canvas((934, 282), "#23272a")) profile = Editor("assets/pfp.png").resize((190, 190)).circle_image() # For profile to use users profile picture load it from url using the load_image/load_image_async function # profile_image = load_image(str(ctx.author.avatar_url)) # profile = Editor(profile_image).resize((150, 150)).circle_image() poppins = Font.poppins(size=30) background.rectangle((20, 20), 894, 242, "#2a2e35") background.paste(profile, (50, 50)) background.ellipse((42, 42), width=206, height=206, outline="#43b581", stroke_width=10) background.rectangle((260, 180), width=630, height=40, fill="#484e4e", radius=20) background.bar( (260, 180), max_width=630, height=40, percentage=user_data["percentage"], fill="#00fa81", radius=20, ) background.text((270, 120), user_data["name"], font=poppins, color="#00fa81") background.text( (870, 125), f"{user_data['xp']} / {user_data['next_level_xp']}", font=poppins, color="#00fa81", align="right", ) rank_level_texts = [ Text("Rank ", color="#00fa81", font=poppins), Text(f"{user_data['rank']}", color="#1EAAFF", font=poppins), Text(" Level ", color="#00fa81", font=poppins), Text(f"{user_data['level']}", color="#1EAAFF", font=poppins), ] background.multicolor_text((850, 30), texts=rank_level_texts, align="right") background.show() ``` -------------------------------- ### easy-pil Text Class API Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/easy_pil/easy_pil.text.rst Provides detailed API documentation for the Text class, including its methods for text rendering, font handling, and color manipulation on images. ```APIDOC easy_pil.text.Text __init__(self, text: str, font: str = None, font_size: int = 10, color: tuple = (0, 0, 0), stroke_width: int = 0, stroke_color: tuple = (0, 0, 0), align: str = 'left', direction: str = 'ltr', spacing: int = 4, features: list = None, language: str = None, kerning: bool = True) Initializes the Text object. Parameters: text (str): The text string to render. font (str, optional): Path to the font file. Defaults to None (uses default font). font_size (int, optional): The size of the font. Defaults to 10. color (tuple, optional): The color of the text in RGB format. Defaults to (0, 0, 0) (black). stroke_width (int, optional): The width of the text stroke. Defaults to 0. stroke_color (tuple, optional): The color of the text stroke in RGB format. Defaults to (0, 0, 0) (black). align (str, optional): Text alignment ('left', 'center', 'right'). Defaults to 'left'. direction (str, optional): Text direction ('ltr', 'rtl'). Defaults to 'ltr'. spacing (int, optional): Line spacing. Defaults to 4. features (list, optional): List of OpenType font features. Defaults to None. language (str, optional): Language code for text shaping. Defaults to None. kerning (bool, optional): Whether to use kerning. Defaults to True. draw(self, image: Image.Image, xy: tuple, anchor: str = 'lt', spacing: int = None, align: str = None, direction: str = None, features: list = None, language: str = None, kerning: bool = None) Draws the text onto an image. Parameters: image (Image.Image): The PIL Image object to draw on. xy (tuple): The (x, y) coordinates to draw the text. anchor (str, optional): The anchor point for the text ('lt', 'mm', 'rb', etc.). Defaults to 'lt' (left-top). spacing (int, optional): Overrides the default line spacing. align (str, optional): Overrides the default text alignment. direction (str, optional): Overrides the default text direction. features (list, optional): Overrides the default font features. language (str, optional): Overrides the default language code. kerning (bool, optional): Overrides the default kerning setting. Returns: Image.Image: The image with the text drawn on it. get_size(self, spacing: int = None, align: str = None, direction: str = None, features: list = None, language: str = None, kerning: bool = None) Calculates the size of the rendered text. Parameters: spacing (int, optional): Line spacing to consider. align (str, optional): Text alignment to consider. direction (str, optional): Text direction to consider. features (list, optional): Font features to consider. language (str, optional): Language code to consider. kerning (bool, optional): Kerning setting to consider. Returns: tuple: A tuple containing the width and height of the text. get_lines(self, width: int, spacing: int = None, align: str = None, direction: str = None, features: list = None, language: str = None, kerning: bool = None) Splits the text into lines that fit within a specified width. Parameters: width (int): The maximum width for the lines. spacing (int, optional): Line spacing to consider. align (str, optional): Text alignment to consider. direction (str, optional): Text direction to consider. features (list, optional): Font features to consider. language (str, optional): Language code to consider. kerning (bool, optional): Kerning setting to consider. Returns: list: A list of strings, where each string is a line of text. get_width(self, spacing: int = None, align: str = None, direction: str = None, features: list = None, language: str = None, kerning: bool = None) Calculates the width of the rendered text. Parameters: spacing (int, optional): Line spacing to consider. align (str, optional): Text alignment to consider. direction (str, optional): Text direction to consider. features (list, optional): Font features to consider. language (str, optional): Language code to consider. kerning (bool, optional): Kerning setting to consider. Returns: int: The width of the text. get_height(self, spacing: int = None, align: str = None, direction: str = None, features: list = None, language: str = None, kerning: bool = None) Calculates the height of the rendered text. Parameters: spacing (int, optional): Line spacing to consider. align (str, optional): Text alignment to consider. direction (str, optional): Text direction to consider. features (list, optional): Font features to consider. language (str, optional): Language code to consider. kerning (bool, optional): Kerning setting to consider. Returns: int: The height of the text. set_text(self, text: str) Sets or updates the text content. Parameters: text (str): The new text string. set_font(self, font: str, font_size: int = None) Sets or updates the font and font size. Parameters: font (str): Path to the font file. font_size (int, optional): The new font size. set_color(self, color: tuple, stroke_color: tuple = None, stroke_width: int = None) Sets or updates the text color and stroke properties. Parameters: color (tuple): The new text color in RGB format. stroke_color (tuple, optional): The new stroke color in RGB format. stroke_width (int, optional): The new stroke width. set_align(self, align: str, direction: str = None, spacing: int = None) Sets or updates the text alignment, direction, and spacing. Parameters: align (str): The new text alignment. direction (str, optional): The new text direction. spacing (int, optional): The new line spacing. ``` -------------------------------- ### Easy-PIL Modules Overview Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/easy_pil/modules.rst This section outlines the different modules available within the Easy-PIL library, each serving a specific purpose in image manipulation. ```APIDOC easy_pil.canvas - Provides functionality for creating and manipulating image canvases. easy_pil.editor - Offers tools for editing and transforming images. easy_pil.workspace - Manages the image editing environment and workspace. easy_pil.font - Handles font loading and text rendering configurations. easy_pil.text - Contains utilities for drawing text on images. easy_pil.utils - Includes various utility functions for image processing tasks. ``` -------------------------------- ### Async Image Editing with AioEditor Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/pages/aio.rst This snippet shows how to use the AioEditor for asynchronous image manipulation. It demonstrates initializing the editor, drawing a rectangle on the image, and executing the changes to obtain the modified image object. ```python from easy_pil import AioEditor editor = AioEditor(your_image) editor.rectangle((0, 0), width=100, height=100, color="black") img = await editor.execute() # returns Editor # now use `img` in the old way ``` -------------------------------- ### easy-pil Font Class Documentation Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/easy_pil/easy_pil.font.rst Documentation for the Font class, which handles font loading and manipulation for image text rendering. It includes methods for creating Font objects, setting font properties, and applying them to text on images. ```APIDOC easy_pil.font.Font __init__(font_path: str, font_size: int) Initializes a Font object. Parameters: font_path: The file path to the font file (e.g., .ttf, .otf). font_size: The desired size of the font. get_font_path() -> str Returns the file path of the loaded font. get_font_size() -> int Returns the current size of the font. set_font_size(size: int) Sets a new font size for the Font object. Parameters: size: The new font size. get_font_name() -> str Returns the name of the font file. get_font_family() -> str Returns the font family name if available from the font file. ``` -------------------------------- ### easy-pil Workspace Class Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/easy_pil/easy_pil.workspace.rst Provides documentation for the Workspace class, including all its members and undocumented attributes. This class is likely used for managing image-related workspaces or operations within the easy-pil library. ```APIDOC .. autoclass:: easy_pil.workspace.Workspace :members: :undoc-members: ``` -------------------------------- ### Discord Bot Avatar Circularization with Easy-PIL Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/pages/discordbot.rst This Python code snippet shows how to create a Discord bot using the Nextcord library. It defines a command 'circle' that fetches the author's avatar, applies a circular mask using easy-pil's Editor and circle_image() method, and then sends the modified image back to the Discord channel. ```python from nextcord import File from nextcord.ext.commands import Bot from easy_pil import Editor, load_image_async bot = Bot(command_prefix='!') @bot.command() async def circle(ctx): # Load the image using `load_image_async` method image = await load_image_async(ctx.author.display_avatar.url) # Initialize the editor and pass image as a parameter editor = Editor(image).circle_image() # Creating nextcord.File object from image_bytes from editor file = File(fp=editor.image_bytes, filename='circle.png') await ctx.send(file=file) bot.run("TOKEN") ``` -------------------------------- ### easy-pil Editor Class Methods Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/easy_pil/easy_pil.editor.rst Provides a comprehensive list of methods available within the Editor class for image editing operations. This includes functionalities for drawing, text rendering, and image manipulation. ```APIDOC easy_pil.editor.Editor :members: :undoc-members: ``` -------------------------------- ### Canvas Class Documentation Source: https://github.com/shahriyardx/easy-pil/blob/master/docs/easy_pil/easy_pil.canvas.rst Documentation for the Canvas class, which serves as the primary interface for image manipulation in easy-pil. It includes methods for drawing shapes, text, and applying filters. ```APIDOC easy_pil.canvas.Canvas Methods: __init__(self, width: int, height: int, color: Union[str, Tuple[int, int, int]] = (255, 255, 255)) Initializes a new Canvas object. Parameters: width: The width of the canvas in pixels. height: The height of the canvas in pixels. color: The background color of the canvas. Can be a color name string (e.g., 'white', 'red') or an RGB tuple (e.g., (255, 0, 0)). Defaults to white. save(self, path: str, format: Optional[str] = None) Saves the canvas to a file. Parameters: path: The file path to save the image to. format: The image format (e.g., 'PNG', 'JPEG'). If None, it's inferred from the file extension. draw_text(self, text: str, position: Tuple[int, int], font: Optional[easy_pil.font.Font] = None, color: Union[str, Tuple[int, int, int]] = (0, 0, 0), align: str = 'left') Draws text on the canvas. Parameters: text: The text string to draw. position: A tuple (x, y) representing the starting position of the text. font: An optional Font object to use for rendering the text. color: The color of the text. Can be a color name string or an RGB tuple. Defaults to black. align: The text alignment ('left', 'center', 'right'). Defaults to 'left'. draw_rectangle(self, position: Tuple[int, int], size: Tuple[int, int], color: Union[str, Tuple[int, int, int]], outline: Optional[Union[str, Tuple[int, int, int]]] = None, width: int = 1) Draws a rectangle on the canvas. Parameters: position: A tuple (x, y) representing the top-left corner of the rectangle. size: A tuple (width, height) representing the dimensions of the rectangle. color: The fill color of the rectangle. Can be a color name string or an RGB tuple. outline: The color of the rectangle's border. If None, no border is drawn. width: The width of the border in pixels. Defaults to 1. draw_circle(self, position: Tuple[int, int], radius: int, color: Union[str, Tuple[int, int, int]], outline: Optional[Union[str, Tuple[int, int, int]]] = None, width: int = 1) Draws a circle on the canvas. Parameters: position: A tuple (x, y) representing the center of the circle. radius: The radius of the circle. color: The fill color of the circle. Can be a color name string or an RGB tuple. outline: The color of the circle's border. If None, no border is drawn. width: The width of the border in pixels. Defaults to 1. apply_blur(self, radius: int) Applies a Gaussian blur to the entire canvas. Parameters: radius: The radius of the blur. apply_grayscale(self) Converts the canvas to grayscale. paste(self, image: 'Image', position: Tuple[int, int], alpha: float = 1.0) Pastes another Image object onto the canvas. Parameters: image: The Image object to paste. position: A tuple (x, y) representing the top-left corner where the image will be pasted. alpha: The transparency level of the pasted image (0.0 to 1.0). Defaults to 1.0. get_image(self) -> 'Image' Returns the underlying PIL Image object. Returns: The PIL Image object. Attributes: width (int): The width of the canvas. height (int): The height of the canvas. image (PIL.Image.Image): The underlying PIL Image object. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.