File size: 1,812 Bytes
f12337d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
{
"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
}
|