Use pyQt5 to build a simple picture editor (PhotoEdit)

Table of contents

  1. Project Background and Significance 2
    1.1 Introduction to Project Background 2
    1.2 Significance of Project Completion 2
  2. Requirements analysis 2
    2.1 Basic module requirements 2
    2.2 Basic algorithm requirements 3
    2.3 Basic framework requirements 3
    2.4 Basic UI requirements 3
  3. Summary and Detailed Design 3
    3.1 Design Summary 3
    3.2 Design Process 4
    3.3 Technical Reference 4
  4. Code implementation 5
    4.1 Python version and IDE description 5
    4.2 Related library calls 5
    4.3 File segmentation description 6
    4.4 Key code description 6
    4.4.1 Filter file code description 6
    4.4.2 Image processing file code description 8
    4.4.3 Image configuration file Code description: 11
    4.4.4 Layout and main program file code description: 13
  5. Code test 20
    5.1 Run and enter the main interface 20
    5.2 Upload picture function test 21
  6. Conclusion and future directions 24
    6.1 Conclusion 24
    6.2 Future directions 24
  7. Acknowledgments 25
  8. References and links25
  9. Requirements Analysis
    2.1 Basic Module Requirements
    For a basic graphics processing software, it includes basic document opening and storage, graphical interface construction, graphics processing, logging, etc. So you need to download relevant modules, including pyQt5, pillow, etc.
    2.2 Basic Algorithm Requirements
    According to any image processing software, image processing related functions will inevitably be used. Some functions also require understanding of its basic algorithms. For example, adding filters requires processing the pixels of the image and calling related functions. Functions, some adjustment functions, such as brightness, contrast, sharpening, these image adjustment methods must also have their own processing algorithms. Therefore, it is necessary to review relevant literature and collect information to obtain the principles and usage of these algorithms.
    2.3 Basic framework requirements
    : By analogy with normal software development specifications, standardize the format of project file creation, learn basic development points, annotation specifications, object-oriented development methods, whether it is necessary to call a large framework, etc.
    2.4 Basic UI requirements
    In order to make the UI interface more beautiful, some picture selection, font selection planning, layout planning and design, etc. are required.
  10. Summary and Detailed Design
    3.1 Design Summary
    Focusing on the major function of image editing and processing, the following work directions were mainly considered during the design:
    1. Design the layout of the main interface window: adopt the editing main window + processing option window design.
    2. Analyze the basic functions to be added: mainly include filter, adjustment, size, and rotation to refine the functions.
    Filter: original image without filter, black and white filter, negative filter, mean filter.
    Adjustments: Contrast, Brightness, Sharpening.
    Dimensions: Modify width, modify height, modify proportion.
    Rotation: 90-degree clockwise and counterclockwise rotation, vertical and horizontal flipping.
    3. Analyze functions and conduct data collection and processing: refine processing matters.
    4. Analyze the level and function of the code that needs to be written: Divide the code into blocks according to functional classification, so that the entire file has a sense of hierarchy.
    5. Start writing code: refine it according to different functions.
    6. UI layout optimization and detail adjustment.
    7. Program debugging and modification.
import getopt
import sys
import logging

from img_modifier import img_helper

logger = logging.getLogger()


def init():
    """Get and parse parameters from console"""

    args = sys.argv[1:]

    if len(args) == 0:
        logger.error("-p can't be empty")
        raise ValueError("-p can't be empty")

    logger.debug(f"run with params: {args}")

    # transform arguments from console
    opts, rem = getopt.getopt(args, "p:", ["rotate=", "resize=", "color_filter=", "flip_top", "flip_left"])
    rotate_angle = resize = color_filter = flip_top = flip_left = None

    path = None
    for opt, arg in opts:
        if opt == "-p":
            path = arg
        elif opt == "--rotate":
            rotate_angle = int(arg)
        elif opt == "--resize":
            resize = arg
        elif opt == "--color_filter":
            color_filter = arg
        elif opt == "--flip_top":
            flip_top = True
        elif opt == "--flip_left":
            flip_left = arg

    if not path:
        raise ValueError("No path")

    img = img_helper.get_img(path)
    if rotate_angle:
        img = img_helper.rotate(img, rotate_angle)

    if resize:
        w, h = map(int, resize.split(','))
        img = img_helper.resize(img, w, h)

    if color_filter:
        img = img_helper.color_filter(img, color_filter)

    if flip_left:
        img = img_helper.flip_left(img)

    if flip_top:
        img = img_helper.flip_top(img)

    if __debug__:
        img.show()


if __name__ == "__main__":
    init()

Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here
Insert image description here

Guess you like

Origin blog.csdn.net/newlw/article/details/133156519