(file_path)
| 12 | os.makedirs(compressed_directory) |
| 13 | |
| 14 | def is_image(file_path): |
| 15 | try: |
| 16 | # Try to open the file with Pillow |
| 17 | Image.open(file_path) |
| 18 | return True |
| 19 | except IOError: |
| 20 | # If an error occurs, it's likely not an image |
| 21 | return False |
| 22 | |
| 23 | for filename in os.listdir(directory): |
| 24 | f = os.path.join(directory, filename) |