Skip to Content

Implement the script

A simple Python model script for performing a rotation can be found here (download).

Add it in models/<model_name> directory to perform the operation. In our case, we have a model named “rotation”.

    • manifest.json
    • workflow.yml
        • rotate.py

A copy of the script is shown below :

import sys import json import os.path from PIL import Image # Increase the maximum image pixel size Image.MAX_IMAGE_PIXELS = None if __name__ == "__main__": # TODO manage error correctly input_image = sys.argv[1] input_angle = int(sys.argv[2]) output_path = f'R_{input_angle}_{os.path.basename(input_image)}' try: color_img = Image.open(input_image) rotated = color_img.rotate(float(input_angle) * -1, expand=True) rotated.save(output_path) print(f"Rotated image saved at {output_path}") except FileNotFoundError: print("Error: Input image file not found.") except ValueError: print("Error: Invalid input angle. Please provide a valid numeric angle.")