""" Resize all PNG assets to 40% for Tiled Map Editor Scans all subfolders in assets/ and resizes images """ import os from PIL import Image from pathlib import Path # Configurations SOURCE_DIR = r"c:\novafarma\assets" OUTPUT_DIR = r"c:\novafarma\Slike_za_Tiled" SCALE_FACTOR = 0.4 # 40% of original size def resize_images(): """Resize all PNG images to 40% and save to Slike_za_Tiled""" # Create output directory os.makedirs(OUTPUT_DIR, exist_ok=True) # Track statistics processed = 0 skipped = 0 errors = [] print(f"šŸ” Scanning {SOURCE_DIR} for PNG files...") print(f"šŸ“ Output directory: {OUTPUT_DIR}") print(f"šŸ“ Scale factor: {SCALE_FACTOR * 100}%\n") # Walk through all subdirectories for root, dirs, files in os.walk(SOURCE_DIR): for filename in files: if filename.lower().endswith('.png'): source_path = os.path.join(root, filename) # Create unique output filename (flat structure) # Use relative path to create unique name rel_path = os.path.relpath(source_path, SOURCE_DIR) output_filename = rel_path.replace(os.sep, '_') output_path = os.path.join(OUTPUT_DIR, output_filename) try: # Open and resize image with Image.open(source_path) as img: original_size = img.size new_size = ( int(img.width * SCALE_FACTOR), int(img.height * SCALE_FACTOR) ) # Resize with high-quality resampling resized_img = img.resize(new_size, Image.Resampling.LANCZOS) # Save resized image resized_img.save(output_path, 'PNG', optimize=True) processed += 1 if processed % 50 == 0: print(f"āœ… Processed {processed} images...") except Exception as e: errors.append(f"{filename}: {str(e)}") skipped += 1 # Print summary print(f"\n{'='*60}") print(f"✨ RESIZE COMPLETE!") print(f"{'='*60}") print(f"āœ… Successfully processed: {processed} images") print(f"āš ļø Skipped (errors): {skipped} images") print(f"šŸ“ Output location: {OUTPUT_DIR}") if errors: print(f"\nāŒ Errors encountered:") for error in errors[:10]: # Show first 10 errors print(f" - {error}") if len(errors) > 10: print(f" ... and {len(errors) - 10} more") print(f"\nšŸŽ® Ready for Tiled Map Editor!") if __name__ == "__main__": resize_images()