Hello mr. Would you like some bloat?
All checks were successful
Rebuild signaller for deprived.dev to rebuild site / test_service (push) Successful in 18s
55
static/images/cropper.py
Normal file
|
@ -0,0 +1,55 @@
|
|||
import os
|
||||
import glob
|
||||
from PIL import Image
|
||||
from concurrent.futures import ProcessPoolExecutor, as_completed
|
||||
|
||||
# Directories
|
||||
input_dir = 'spinning_cat'
|
||||
output_dir = 'spinning_cat_cropped'
|
||||
|
||||
# Ensure output directory exists
|
||||
def ensure_output_dir():
|
||||
if not os.path.exists(output_dir):
|
||||
os.makedirs(output_dir)
|
||||
|
||||
# Process a single image: crop transparent borders and save
|
||||
def process_image(filepath):
|
||||
try:
|
||||
img = Image.open(filepath)
|
||||
if img.mode != 'RGBA':
|
||||
img = img.convert('RGBA')
|
||||
alpha = img.split()[-1]
|
||||
bbox = alpha.getbbox()
|
||||
cropped = img.crop(bbox) if bbox else img
|
||||
filename = os.path.basename(filepath)
|
||||
out_path = os.path.join(output_dir, filename)
|
||||
cropped.save(out_path)
|
||||
return out_path, None
|
||||
except Exception as e:
|
||||
return filepath, e
|
||||
|
||||
# Main execution: parallel processing
|
||||
|
||||
def main():
|
||||
ensure_output_dir()
|
||||
pattern = os.path.join(input_dir, 'untitled_*.png')
|
||||
files = sorted(glob.glob(pattern))
|
||||
if not files:
|
||||
print(f"No files found in '{input_dir}' with pattern 'untitled_*.png'.")
|
||||
return
|
||||
|
||||
with ProcessPoolExecutor() as executor:
|
||||
futures = {executor.submit(process_image, fp): fp for fp in files}
|
||||
for future in as_completed(futures):
|
||||
fp = futures[future]
|
||||
out_path, error = future.result()
|
||||
if error:
|
||||
print(f"Error processing {fp}: {error}")
|
||||
else:
|
||||
print(f"Cropped and saved: {out_path}")
|
||||
|
||||
print("Processing complete.")
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
BIN
static/images/spinning_cat/untitled_00001.png
Normal file
After Width: | Height: | Size: 396 KiB |
BIN
static/images/spinning_cat/untitled_00002.png
Normal file
After Width: | Height: | Size: 396 KiB |
BIN
static/images/spinning_cat/untitled_00003.png
Normal file
After Width: | Height: | Size: 398 KiB |
BIN
static/images/spinning_cat/untitled_00004.png
Normal file
After Width: | Height: | Size: 397 KiB |
BIN
static/images/spinning_cat/untitled_00005.png
Normal file
After Width: | Height: | Size: 397 KiB |
BIN
static/images/spinning_cat/untitled_00006.png
Normal file
After Width: | Height: | Size: 397 KiB |
BIN
static/images/spinning_cat/untitled_00007.png
Normal file
After Width: | Height: | Size: 399 KiB |
BIN
static/images/spinning_cat/untitled_00008.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00009.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00010.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00011.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00012.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00013.png
Normal file
After Width: | Height: | Size: 403 KiB |
BIN
static/images/spinning_cat/untitled_00014.png
Normal file
After Width: | Height: | Size: 403 KiB |
BIN
static/images/spinning_cat/untitled_00015.png
Normal file
After Width: | Height: | Size: 403 KiB |
BIN
static/images/spinning_cat/untitled_00016.png
Normal file
After Width: | Height: | Size: 403 KiB |
BIN
static/images/spinning_cat/untitled_00017.png
Normal file
After Width: | Height: | Size: 403 KiB |
BIN
static/images/spinning_cat/untitled_00018.png
Normal file
After Width: | Height: | Size: 403 KiB |
BIN
static/images/spinning_cat/untitled_00019.png
Normal file
After Width: | Height: | Size: 403 KiB |
BIN
static/images/spinning_cat/untitled_00020.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00021.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00022.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00023.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00024.png
Normal file
After Width: | Height: | Size: 403 KiB |
BIN
static/images/spinning_cat/untitled_00025.png
Normal file
After Width: | Height: | Size: 402 KiB |
BIN
static/images/spinning_cat/untitled_00026.png
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
static/images/spinning_cat/untitled_00027.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00028.png
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
static/images/spinning_cat/untitled_00029.png
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
static/images/spinning_cat/untitled_00030.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00031.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00032.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00033.png
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
static/images/spinning_cat/untitled_00034.png
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
static/images/spinning_cat/untitled_00035.png
Normal file
After Width: | Height: | Size: 401 KiB |
BIN
static/images/spinning_cat/untitled_00036.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00037.png
Normal file
After Width: | Height: | Size: 403 KiB |
BIN
static/images/spinning_cat/untitled_00038.png
Normal file
After Width: | Height: | Size: 96 KiB |
BIN
static/images/spinning_cat/untitled_00039.png
Normal file
After Width: | Height: | Size: 97 KiB |
BIN
static/images/spinning_cat/untitled_00040.png
Normal file
After Width: | Height: | Size: 108 KiB |
BIN
static/images/spinning_cat/untitled_00041.png
Normal file
After Width: | Height: | Size: 121 KiB |
BIN
static/images/spinning_cat/untitled_00042.png
Normal file
After Width: | Height: | Size: 129 KiB |
BIN
static/images/spinning_cat/untitled_00043.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
static/images/spinning_cat/untitled_00044.png
Normal file
After Width: | Height: | Size: 68 KiB |
BIN
static/images/spinning_cat/untitled_00045.png
Normal file
After Width: | Height: | Size: 111 KiB |
BIN
static/images/spinning_cat/untitled_00046.png
Normal file
After Width: | Height: | Size: 116 KiB |
BIN
static/images/spinning_cat/untitled_00047.png
Normal file
After Width: | Height: | Size: 118 KiB |
BIN
static/images/spinning_cat/untitled_00048.png
Normal file
After Width: | Height: | Size: 80 KiB |
BIN
static/images/spinning_cat/untitled_00049.png
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
static/images/spinning_cat/untitled_00050.png
Normal file
After Width: | Height: | Size: 113 KiB |
BIN
static/images/spinning_cat/untitled_00051.png
Normal file
After Width: | Height: | Size: 126 KiB |
BIN
static/images/spinning_cat/untitled_00052.png
Normal file
After Width: | Height: | Size: 92 KiB |
BIN
static/images/spinning_cat/untitled_00053.png
Normal file
After Width: | Height: | Size: 63 KiB |
BIN
static/images/spinning_cat/untitled_00054.png
Normal file
After Width: | Height: | Size: 94 KiB |
BIN
static/images/spinning_cat/untitled_00055.png
Normal file
After Width: | Height: | Size: 136 KiB |
BIN
static/images/spinning_cat/untitled_00056.png
Normal file
After Width: | Height: | Size: 116 KiB |
BIN
static/images/spinning_cat/untitled_00057.png
Normal file
After Width: | Height: | Size: 73 KiB |
BIN
static/images/spinning_cat/untitled_00058.png
Normal file
After Width: | Height: | Size: 84 KiB |
BIN
static/images/spinning_cat/untitled_00059.png
Normal file
After Width: | Height: | Size: 109 KiB |
BIN
static/images/spinning_cat/untitled_00060.png
Normal file
After Width: | Height: | Size: 109 KiB |
BIN
static/images/spinning_cat/untitled_00061.png
Normal file
After Width: | Height: | Size: 90 KiB |
BIN
static/images/spinning_cat/untitled_00062.png
Normal file
After Width: | Height: | Size: 76 KiB |
BIN
static/images/spinning_cat/untitled_00063.png
Normal file
After Width: | Height: | Size: 105 KiB |
BIN
static/images/spinning_cat/untitled_00064.png
Normal file
After Width: | Height: | Size: 124 KiB |
BIN
static/images/spinning_cat/untitled_00065.png
Normal file
After Width: | Height: | Size: 114 KiB |
BIN
static/images/spinning_cat/untitled_00066.png
Normal file
After Width: | Height: | Size: 70 KiB |
BIN
static/images/spinning_cat/untitled_00067.png
Normal file
After Width: | Height: | Size: 93 KiB |
BIN
static/images/spinning_cat/untitled_00068.png
Normal file
After Width: | Height: | Size: 110 KiB |
BIN
static/images/spinning_cat/untitled_00069.png
Normal file
After Width: | Height: | Size: 117 KiB |
BIN
static/images/spinning_cat/untitled_00070.png
Normal file
After Width: | Height: | Size: 78 KiB |
BIN
static/images/spinning_cat/untitled_00071.png
Normal file
After Width: | Height: | Size: 81 KiB |
BIN
static/images/spinning_cat/untitled_00072.png
Normal file
After Width: | Height: | Size: 115 KiB |
BIN
static/images/spinning_cat/untitled_00073.png
Normal file
After Width: | Height: | Size: 121 KiB |
BIN
static/images/spinning_cat/untitled_00074.png
Normal file
After Width: | Height: | Size: 128 KiB |
BIN
static/images/spinning_cat/untitled_00075.png
Normal file
After Width: | Height: | Size: 66 KiB |
BIN
static/images/spinning_cat/untitled_00076.png
Normal file
After Width: | Height: | Size: 102 KiB |
BIN
static/images/spinning_cat/untitled_00077.png
Normal file
After Width: | Height: | Size: 114 KiB |
BIN
static/images/spinning_cat/untitled_00078.png
Normal file
After Width: | Height: | Size: 136 KiB |
BIN
static/images/spinning_cat/untitled_00079.png
Normal file
After Width: | Height: | Size: 126 KiB |
BIN
static/images/spinning_cat/untitled_00080.png
Normal file
After Width: | Height: | Size: 95 KiB |
BIN
static/images/spinning_cat/untitled_00081.png
Normal file
After Width: | Height: | Size: 126 KiB |
BIN
static/images/spinning_cat/untitled_00082.png
Normal file
After Width: | Height: | Size: 389 KiB |
BIN
static/images/spinning_cat/untitled_00083.png
Normal file
After Width: | Height: | Size: 388 KiB |
BIN
static/images/spinning_cat/untitled_00084.png
Normal file
After Width: | Height: | Size: 388 KiB |
BIN
static/images/spinning_cat/untitled_00085.png
Normal file
After Width: | Height: | Size: 384 KiB |
BIN
static/images/spinning_cat/untitled_00086.png
Normal file
After Width: | Height: | Size: 385 KiB |
BIN
static/images/spinning_cat/untitled_00087.png
Normal file
After Width: | Height: | Size: 384 KiB |
BIN
static/images/spinning_cat/untitled_00088.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00089.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00090.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00091.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00092.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00093.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00094.png
Normal file
After Width: | Height: | Size: 400 KiB |
BIN
static/images/spinning_cat/untitled_00095.png
Normal file
After Width: | Height: | Size: 399 KiB |
BIN
static/images/spinning_cat/untitled_00096.png
Normal file
After Width: | Height: | Size: 399 KiB |
BIN
static/images/spinning_cat/untitled_00097.png
Normal file
After Width: | Height: | Size: 399 KiB |
BIN
static/images/spinning_cat/untitled_00098.png
Normal file
After Width: | Height: | Size: 399 KiB |
BIN
static/images/spinning_cat/untitled_00099.png
Normal file
After Width: | Height: | Size: 399 KiB |