Created
June 7, 2025 02:35
-
-
Save harrisonrw/1e5f9db31f892adc0734baca68a3252e to your computer and use it in GitHub Desktop.
Script to find and resize screenshots with fastlane size bugs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| """ | |
| Filename: resize_device_screenshots.py | |
| Author: Robert Harrison | |
| Date: June 6, 2025 | |
| Description: Script to find and resize PNG screenshots for devices with fastlane size bugs. | |
| Uses ImageMagick mogrify to resize images to proper resolutions while maintaining | |
| aspect ratio and centering content. | |
| Usage: python resize_device_screenshots.py <search_directory> | |
| Example: python resize_device_screenshots.py ./screenshots | |
| """ | |
| import os | |
| import glob | |
| import sys | |
| import subprocess | |
| # Check if directory argument is provided | |
| if len(sys.argv) != 2: | |
| print("Usage: python script.py <search_directory>") | |
| sys.exit(1) | |
| # Directory to search for files from command line argument | |
| search_directory = sys.argv[1] | |
| # Check if the directory exists | |
| if not os.path.isdir(search_directory): | |
| print(f"Error: Directory '{search_directory}' does not exist.") | |
| sys.exit(1) | |
| # A list device names and proper resolutions. | |
| devices = [ | |
| ("iPhone 14 Pro", "1179x2556"), | |
| ("iPhone 15", "1179x2556"), | |
| ("iPhone 15 Pro", "1179x2556") | |
| ] | |
| print("Resizing screenshots for any devices with fastlane size bugs...") | |
| # Iterate devices_with_bugs to find matching files in the directory. | |
| for device_name, resolution in devices: | |
| # Search for PNG files with device name as prefix in the specified directory | |
| pattern = os.path.join(search_directory, f"{device_name}-*.png") | |
| matching_files = glob.glob(pattern) | |
| # Print the path to the matching file(s). | |
| if matching_files: | |
| print(f"Found screenshots from buggy device: {device_name}. Resizing to resolution: {resolution}...") | |
| for file_path in matching_files: | |
| print(f" {os.path.abspath(file_path)}") | |
| # Use ImageMagick mogrify to resize the file | |
| try: | |
| cmd = ["mogrify", "-resize", resolution, "-gravity", "center", "-extent", resolution, file_path] | |
| subprocess.run(cmd, check=True, capture_output=True) | |
| print(f" β Successfully resized to {resolution}") | |
| except subprocess.CalledProcessError as e: | |
| print(f" π Error resizing file: {e}") | |
| except FileNotFoundError: | |
| print(" π Error: ImageMagick not found. Please install ImageMagick.") | |
| else: | |
| print(f"No files found for {device_name} ({resolution})") | |
| print() # Empty line for readability |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment