from PIL import Image
import sys
import json

def trim_white_space(input_path, output_path):
    image = Image.open(input_path)
    trimmed = image.crop(image.getbbox())  # Auto-trim based on non-transparent pixels
    trimmed.save(output_path)

if __name__ == "__main__":
    # Read JSON data from stdin
    input_data = json.load(sys.stdin)

    # Extract file paths from the input data
    input_file = input_data['input_file']
    output_file = input_data['output_file']

    try:
        # Call the function to trim the white space
        trim_white_space(input_file, output_file)

        # Return success message in JSON format
        response = {'status': True}
    except Exception as e:
        response = {'status': False, 'message': str(e)}

    # Output the result in JSON format
    print(json.dumps(response))
