commit all assets

I should have done this a long time ago
This commit is contained in:
2025-12-20 23:13:40 -07:00
parent 9f2fff92d5
commit 61618b98ce
17 changed files with 383 additions and 0 deletions
BIN
View File
Binary file not shown.
Binary file not shown.
Binary file not shown.
+29
View File
@@ -0,0 +1,29 @@
@echo off
REM Check if Python is installed
where python >nul 2>&1
if errorlevel 1 (
echo Python is not installed or not in PATH.
pause
exit /b
)
REM Check if a file was dragged onto the script
if "%~1"=="" (
echo No image file was dragged onto the script.
pause
exit /b
)
REM Get the frame image path
set "frame_image_path=MOTDFrame.png" REM Path to the frame image
REM Get the directory of the batch file
set "script_dir=%~dp0"
REM Run the Python script with all dragged images and the frame image
python "%script_dir%FrameTool.py" %* "%script_dir%%frame_image_path%"
REM Run Thumbs.py after FrameTool.py finishes without passing any arguments
python "%script_dir%Thumbs.py"
pause
+118
View File
@@ -0,0 +1,118 @@
import os
import sys
from PIL import Image
def process_image(input_image_path, frame_image_path, output_path):
"""
Process the input image and frame, creating a simple composite PNG
Args:
input_image_path: Path to the input image
frame_image_path: Path to the frame image (PNG with transparency)
output_path: Path where the output will be saved
Returns:
True if successful, False otherwise
"""
try:
# Open the images
print(f"Opening input image: {input_image_path}")
input_image = Image.open(input_image_path).convert("RGBA")
print(f"Opening frame image: {frame_image_path}")
frame_image = Image.open(frame_image_path).convert("RGBA")
# Get dimensions of the frame
frame_width, frame_height = frame_image.size
print(f"Frame dimensions: {frame_width}x{frame_height}")
# Resize input image to 904x904
input_image = input_image.resize((904, 904), Image.LANCZOS)
# Calculate position to center the input image
input_width, input_height = input_image.size
input_x = (frame_width - input_width) // 2
input_y = (frame_height - input_height) // 2
# Position the input image on a transparent background
positioned_input = Image.new("RGBA", (frame_width, frame_height), (0, 0, 0, 0))
positioned_input.paste(input_image, (input_x, input_y))
# Create a composite image
composite = Image.new("RGBA", (frame_width, frame_height), (0, 0, 0, 0))
composite.paste(positioned_input, (0, 0))
composite.paste(frame_image, (0, 0), frame_image)
# Save the composite image
composite.save(output_path, "PNG")
print(f"Saved composite image: {output_path}")
return True
except Exception as e:
print(f"Error processing image: {e}")
import traceback
traceback.print_exc()
return False
def main():
# Print command line arguments for debugging
print(f"Command line arguments: {sys.argv}")
# Check if at least one input image is provided
if len(sys.argv) < 3:
print("Usage: python FrameTool.py <input_image_path> <frame_image_path>")
print(" or: python FrameTool.py <input_image_path1> <input_image_path2> ... <frame_image_path>")
return
# Get the frame image path from the last argument
frame_image_path = sys.argv[-1] # The last argument is the frame image
print(f"Frame image path: {frame_image_path}")
# Check if the frame image exists
if not os.path.exists(frame_image_path):
print(f"Frame image not found: {frame_image_path}")
return
# Get the directory of the script for output
script_dir = os.path.dirname(os.path.abspath(__file__))
print(f"Script directory: {script_dir}")
# Process each input image
input_images = sys.argv[1:-1] # Exclude the last argument (frame image path)
print(f"Input images to process: {input_images}")
for input_image_path in input_images:
# Check if the input image exists
if not os.path.exists(input_image_path):
print(f"Input image not found: {input_image_path}")
continue
print(f"Processing input image: {input_image_path}")
# Generate a unique output image path in the script directory
output_image_path = os.path.join(script_dir, "output.png") # Start with output.png
# Ensure the output file does not overwrite existing files
counter = 1
while os.path.exists(output_image_path):
output_image_path = os.path.join(script_dir, f"output_{counter}.png")
counter += 1
print(f"Output image path: {output_image_path}")
# Process the image
success = process_image(input_image_path, frame_image_path, output_image_path)
if success:
print(f"Successfully processed and saved {input_image_path}.")
else:
print(f"Failed to process {input_image_path}.")
# Add a try-except block to catch and print any errors
if __name__ == "__main__":
try:
main()
except Exception as e:
print(f"Error in main: {e}")
import traceback
traceback.print_exc()
+110
View File
@@ -0,0 +1,110 @@
import cv2
import os
import sys
import numpy as np
def fit_image_to_frame(input_image_path, frame_image_path):
try:
# Read the input image and the frame image
input_image = cv2.imread(input_image_path, cv2.IMREAD_UNCHANGED) # Read with alpha channel if present
frame_image = cv2.imread(frame_image_path, cv2.IMREAD_UNCHANGED) # Read with alpha channel if present
# Check if images were loaded successfully
if input_image is None or frame_image is None:
raise ValueError("Error loading images. Please check the file paths.")
# Print the shapes and types for debugging
print(f"Input image shape: {input_image.shape}, Frame image shape: {frame_image.shape}")
# Resize the input image to 904x904
input_image = cv2.resize(input_image, (904, 904), interpolation=cv2.INTER_LANCZOS4)
# Create a new image with the same size as the frame
combined_image = np.zeros_like(frame_image) # Initialize with zeros (black background)
# Calculate position to center the input image
input_x = (frame_image.shape[1] - input_image.shape[1]) // 2
input_y = (frame_image.shape[0] - input_image.shape[0]) // 2
# First, place the input image in the center of the combined image
if input_image.shape[2] == 4: # RGBA
# For RGBA images, we need to handle the alpha channel
for c in range(0, 3): # For each color channel (RGB)
combined_image[input_y:input_y + input_image.shape[0], input_x:input_x + input_image.shape[1], c] = input_image[:, :, c]
# Copy the alpha channel
combined_image[input_y:input_y + input_image.shape[0], input_x:input_x + input_image.shape[1], 3] = input_image[:, :, 3]
else: # RGB
# For RGB images, we need to create an alpha channel
for c in range(0, 3): # For each color channel (RGB)
combined_image[input_y:input_y + input_image.shape[0], input_x:input_x + input_image.shape[1], c] = input_image[:, :, c]
# Set the alpha channel to fully opaque
combined_image[input_y:input_y + input_image.shape[0], input_x:input_x + input_image.shape[1], 3] = 255
# Now, overlay the frame on top of the combined image
# The frame's alpha channel will determine how much of the input image shows through
frame_alpha = frame_image[:, :, 3] / 255.0 # Normalize alpha channel to [0, 1]
for c in range(0, 3): # For each color channel (RGB)
combined_image[:, :, c] = (1 - frame_alpha) * combined_image[:, :, c] + frame_alpha * frame_image[:, :, c]
# Ensure the alpha channel is preserved
combined_image[:, :, 3] = np.maximum(combined_image[:, :, 3], frame_image[:, :, 3])
return combined_image # Return the combined image
except Exception as e:
print(f"Error: {e}") # Print the error message for debugging
return None # Return None if there was an error
def save_as_jpg(output_image, output_path, quality=95):
# Save the combined image as a JPG file with specified quality
# JPG doesn't support alpha channel, so we need to convert to BGR
if output_image.shape[2] == 4: # If RGBA
# Create white background
background = np.ones_like(output_image, dtype=np.uint8) * 255
# Only use RGB channels for JPG
mask = output_image[:,:,3:] / 255.0
output_image_rgb = output_image[:,:,:3]
background[:,:,:3] = background[:,:,:3] * (1 - mask) + output_image_rgb * mask
# Save as JPG
cv2.imwrite(output_path, background[:,:,:3], [cv2.IMWRITE_JPEG_QUALITY, quality])
else:
# Save as JPG
cv2.imwrite(output_path, output_image, [cv2.IMWRITE_JPEG_QUALITY, quality])
if __name__ == "__main__":
# Check if at least one input image is provided
if len(sys.argv) < 3: # Ensure at least one input image and one frame image
print("Usage: python FrameTool.py <input_image_path1> <input_image_path2> ... <frame_image_path>")
sys.exit(1)
# Get the frame image path from the last argument
frame_image_path = sys.argv[-1] # The last argument is the frame image
# Check if the frame image exists
if not os.path.exists(frame_image_path):
print(f"Frame image not found: {frame_image_path}")
sys.exit(1)
# Get the directory of the script for output
script_dir = os.path.dirname(os.path.abspath(__file__))
# Process each input image
for input_image_path in sys.argv[1:-1]: # Exclude the last argument (frame image path)
# Generate a unique output image path in the script directory
output_image_path = os.path.join(script_dir, "output.jpg") # Start with output.jpg
# Ensure the output file does not overwrite existing files
counter = 1
while os.path.exists(output_image_path):
output_image_path = os.path.join(script_dir, f"output_{counter}.jpg")
counter += 1
# Call the function to fit the image to the frame
combined_image = fit_image_to_frame(input_image_path, frame_image_path)
# Save the combined image if it was created successfully
if combined_image is not None:
save_as_jpg(combined_image, output_image_path) # Save the combined image as JPG
print(f"JPG saved successfully at: {output_image_path}") # Log success
else:
print(f"Failed to process {input_image_path}.")
BIN
View File
Binary file not shown.
Binary file not shown.
+84
View File
@@ -0,0 +1,84 @@
from PIL import Image
import os
import sys
import glob
def create_thumbnail(input_image_path, background_path, rainy_still_path):
try:
print(f"Processing input image: {input_image_path}")
# Open the images and ensure they are in RGBA mode
input_image = Image.open(input_image_path).convert("RGBA")
background_image = Image.open(background_path).convert("RGBA")
rainy_still_image = Image.open(rainy_still_path).convert("RGBA")
# Scale the input image up by 5%
scaled_width = int(input_image.width * 1.05)
scaled_height = int(input_image.height * 1.05)
input_image = input_image.resize((scaled_width, scaled_height), Image.LANCZOS)
# Create a new image with the same size as the background
combined_image = Image.new('RGBA', background_image.size)
# Paste the background
combined_image.paste(background_image, (0, 0))
# Calculate position to center the input image
input_x = (combined_image.width - input_image.width) // 2
input_y = (combined_image.height - input_image.height) // 2
# Paste the input image on top
combined_image.paste(input_image, (input_x, input_y), input_image)
# Move RainyStill down and to the right by 783 pixels
rainy_still_position = (783, 783) # Adjust as needed
combined_image.paste(rainy_still_image, rainy_still_position, rainy_still_image)
return combined_image # Return the combined image
except Exception as e:
print(f"Error: {e}") # Print the error message for debugging
return None # Return None if there was an error
if __name__ == "__main__":
# Define the paths for the background and RainyStill images
script_dir = os.path.dirname(os.path.abspath(__file__))
background_path = os.path.join(script_dir, "background.png")
rainy_still_path = os.path.join(script_dir, "RainyStill.png")
# Check if the background and RainyStill images exist
if not os.path.exists(background_path):
print(f"Background image not found: {background_path}")
sys.exit(1)
if not os.path.exists(rainy_still_path):
print(f"RainyStill image not found: {rainy_still_path}")
sys.exit(1)
# Find all output* files in the current directory
output_files = glob.glob(os.path.join(script_dir, "output*"))
# Process each output file
for input_image_path in output_files:
# Generate a unique output image path in the script directory
output_image_path = os.path.join(script_dir, "output_thumb.jpg") # Start with output_thumb.jpg
# Ensure the output file does not overwrite existing files
counter = 1
while os.path.exists(output_image_path):
output_image_path = os.path.join(script_dir, f"output_thumb_{counter}.jpg")
counter += 1
# Call the function to create the thumbnail
combined_image = create_thumbnail(input_image_path, background_path, rainy_still_path)
# Save the combined image if it was created successfully
if combined_image is not None:
# Convert to RGB mode for JPG (JPG doesn't support alpha)
rgb_image = Image.new("RGB", combined_image.size, (255, 255, 255))
rgb_image.paste(combined_image, mask=combined_image.split()[3]) # Use alpha as mask
# Save as JPG with quality parameter to control file size
rgb_image.save(output_image_path, format='JPEG', quality=100) # Higher quality for better image fidelity
print(f"JPG saved successfully at: {output_image_path}") # Log success
else:
print(f"Failed to process {input_image_path}.")
Binary file not shown.
Binary file not shown.
+9
View File
@@ -0,0 +1,9 @@
@echo off
echo Installing required Python packages...
pip install Pillow
pip install psd-tools
pip install psd-tools2
echo All dependencies have been installed.
pause
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.
BIN
View File
Binary file not shown.