Skip to content

Commit

Permalink
Add support for .webp images. (#153)
Browse files Browse the repository at this point in the history
* Add support for `.webp` images.

WebP images are getting increasingly more common, and Pillow supports this format. Adding it to the list of valid formats is the only change required to make this work.

* Add `.webp` to supported formats in docs

* Convert test image to WEBP and add to tests
  • Loading branch information
Wicloz authored Jan 10, 2023
1 parent cd7a946 commit a2b0837
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion imagededup/utils/image_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from imagededup.utils.logger import return_logger


IMG_FORMATS = ['JPEG', 'PNG', 'BMP', 'MPO', 'PPM', 'TIFF', 'GIF']
IMG_FORMATS = ['JPEG', 'PNG', 'BMP', 'MPO', 'PPM', 'TIFF', 'GIF', 'WEBP']
logger = return_logger(__name__)


Expand Down
4 changes: 2 additions & 2 deletions mkdocs/docs/user_guide/encoding_generation.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ The 'method-name' corresponds to one of the deduplication methods available and

- If an image in the image directory can't be loaded, no encodings are generated for the image. Hence, there is no entry
for the image in the returned encodings dictionary.
- Supported image formats: 'JPEG', 'PNG', 'BMP', 'MPO', 'PPM', 'TIFF', 'GIF', 'SVG', 'PGM', 'PBM'.
- Supported image formats: 'JPEG', 'PNG', 'BMP', 'MPO', 'PPM', 'TIFF', 'GIF', 'SVG', 'PGM', 'PBM', 'WEBP'.

#### Examples

Expand Down Expand Up @@ -74,7 +74,7 @@ array if cnn is used.
#### Considerations

- If the image can't be loaded, no encodings are generated for the image and *None* is returned.
- Supported image formats: 'JPEG', 'PNG', 'BMP', 'MPO', 'PPM', 'TIFF', 'GIF', 'SVG', 'PGM', 'PBM'.
- Supported image formats: 'JPEG', 'PNG', 'BMP', 'MPO', 'PPM', 'TIFF', 'GIF', 'SVG', 'PGM', 'PBM', 'WEBP'.

#### Examples

Expand Down
Binary file added tests/data/formats_images/ukbench09380.webp
Binary file not shown.
3 changes: 3 additions & 0 deletions tests/test_cnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ def test__get_cnn_features_batch(cnn):
'ukbench09380.jpeg',
'ukbench09380.png',
'ukbench09380.svg',
'ukbench09380.webp',
]

assert list(sorted(result.keys(), key=str.lower)) == expected_predicted_files
Expand Down Expand Up @@ -204,6 +205,7 @@ def test_encode_images(cnn):
'ukbench09380.jpeg',
'ukbench09380.png',
'ukbench09380.svg',
'ukbench09380.webp',
]

assert list(sorted(result.keys(), key=str.lower)) == expected_predicted_files
Expand All @@ -225,6 +227,7 @@ def test_encode_images(cnn):
'ukbench09380.jpeg',
'ukbench09380.png',
'ukbench09380.svg',
'ukbench09380.webp',
]

assert list(sorted(result.keys(), key=str.lower)) == expected_predicted_files
Expand Down

0 comments on commit a2b0837

Please sign in to comment.