{ "cells": [ { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "import os\n", "from PIL import Image\n", "\n", "# Disable image resolution limit.\n", "Image.MAX_IMAGE_PIXELS = None\n", "\n", "def find_images_with_transparency(directory):\n", " transparent_images = []\n", "\n", " for root, dirs, files in os.walk(directory):\n", " for file in files:\n", " if file.lower().endswith(('.jpg', '.jpeg', '.png')):\n", " file_path = os.path.join(root, file)\n", " try:\n", " with Image.open(file_path) as img:\n", " if img.mode in ('RGBA', 'LA') or (img.mode == 'P' and 'transparency' in img.info):\n", " transparent_images.append(os.path.normpath(file_path))\n", " except Exception as e:\n", " print(f\"Error processing {file_path}: {e}\")\n", "\n", " return transparent_images\n", "\n", "if __name__ == \"__main__\":\n", " directory = r'E:\\training_dir'\n", " transparent_images = find_images_with_transparency(directory)\n", " print(\"Images with transparency:\")\n", " for img_path in transparent_images:\n", " print(img_path)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.12.3" } }, "nbformat": 4, "nbformat_minor": 2 }