From 287201a554523a1cb4258ff41ec52ca2bdc0ac13 Mon Sep 17 00:00:00 2001 From: Vincent Sarago Date: Wed, 17 Mar 2021 23:03:41 -0400 Subject: [PATCH] add support for jpeg and jpg (#271) * add support for jpeg and jpg * update changelog --- CHANGES.md | 4 ++++ docs/concepts/output_format.md | 3 ++- setup.py | 2 +- tests/routes/test_cog.py | 10 ++++++++-- tests/routes/test_mosaic.py | 2 +- tests/test_enums.py | 2 ++ titiler/resources/enums.py | 5 ++++- 7 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index da7281fed..aeef75334 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Release Notes +## Next (TBD) + +* add support for `.jpg` and `.jpeg` extensions (https://github.com/developmentseed/titiler/pull/271) + ## 0.2.0 (2021-03-09) * adapt for cogeo-mosaic `3.0.0rc2` and add `backend_options` attribute in MosaicTilerFactory (https://github.com/developmentseed/titiler/pull/247) diff --git a/docs/concepts/output_format.md b/docs/concepts/output_format.md index bef31a44b..b3a8dd419 100644 --- a/docs/concepts/output_format.md +++ b/docs/concepts/output_format.md @@ -12,7 +12,8 @@ Default output types/extensions are: * `.jp2`: image/jp2 * `.png`: image/png * `.pngraw`: image/png -* `.jpg`: image/jpeg +* `.jpeg`: image/jpeg +* `.jpg`: image/jpg * `.webp`: image/webp * `.npy`: application/x-binary diff --git a/setup.py b/setup.py index 134e456d9..f70ddbc68 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ "python-dotenv", "rasterio", "rio-cogeo>=2.1,<2.2", - "rio-tiler>=2.0.4,<2.1", + "rio-tiler>=2.0.5,<2.1", "uvicorn[standard]>=0.12.0,<0.14.0", # Additional requirements for python 3.6 "dataclasses;python_version<'3.7'", diff --git a/tests/routes/test_cog.py b/tests/routes/test_cog.py index d098d0d32..6e8d0ea49 100644 --- a/tests/routes/test_cog.py +++ b/tests/routes/test_cog.py @@ -146,13 +146,19 @@ def test_tile(rio, app): "/cog/tiles/8/87/48.jpg?url=https://myurl.com/cog.tif&rescale=0,1000" ) assert response.status_code == 200 + assert response.headers["content-type"] == "image/jpg" + + response = app.get( + "/cog/tiles/8/87/48.jpeg?url=https://myurl.com/cog.tif&rescale=0,1000" + ) + assert response.status_code == 200 assert response.headers["content-type"] == "image/jpeg" response = app.get( "/cog/tiles/8/87/48@2x.jpg?url=https://myurl.com/cog.tif&rescale=0,1000" ) assert response.status_code == 200 - assert response.headers["content-type"] == "image/jpeg" + assert response.headers["content-type"] == "image/jpg" response = app.get( "/cog/tiles/8/87/48@2x.tif?url=https://myurl.com/cog.tif&nodata=0&bidx=1" @@ -376,7 +382,7 @@ def test_part(rio, app): "/cog/crop/-56.228,72.715,-54.547,73.188.jpg?url=https://myurl.com/cog.tif&rescale=0,1000&max_size=256&return_mask=false" ) assert response.status_code == 200 - assert response.headers["content-type"] == "image/jpeg" + assert response.headers["content-type"] == "image/jpg" meta = parse_img(response.content) assert meta["count"] == 1 assert meta["width"] == 256 diff --git a/tests/routes/test_mosaic.py b/tests/routes/test_mosaic.py index 5c6722288..494e33d72 100644 --- a/tests/routes/test_mosaic.py +++ b/tests/routes/test_mosaic.py @@ -166,7 +166,7 @@ def test_tile(app): }, ) assert response.status_code == 200 - assert response.headers["content-type"] == "image/jpeg" + assert response.headers["content-type"] == "image/jpg" # partial tile response = app.get( diff --git a/tests/test_enums.py b/tests/test_enums.py index 0ac68a02e..a7669b031 100644 --- a/tests/test_enums.py +++ b/tests/test_enums.py @@ -12,6 +12,7 @@ ("png", "PNG", "image/png"), ("npy", "NPY", "application/x-binary"), ("tif", "GTiff", "image/tiff; application=geotiff"), + ("jpg", "JPEG", "image/jpg"), ("jpeg", "JPEG", "image/jpeg"), ("jp2", "JP2OpenJPEG", "image/jp2"), ("webp", "WEBP", "image/webp"), @@ -28,5 +29,6 @@ def test_imageprofile(): """test image profile.""" ImageType.png.profile == img_profiles.get("png") ImageType.pngraw.profile == img_profiles.get("pngraw") + ImageType.jpg.profile == img_profiles.get("jpg") ImageType.jpeg.profile == img_profiles.get("jpeg") ImageType.webp.profile == img_profiles.get("webp") diff --git a/titiler/resources/enums.py b/titiler/resources/enums.py index b4e9dd3e3..0f9edba6c 100644 --- a/titiler/resources/enums.py +++ b/titiler/resources/enums.py @@ -15,6 +15,7 @@ class MediaType(str, Enum): png = "image/png" pngraw = "image/png" jpeg = "image/jpeg" + jpg = "image/jpg" webp = "image/webp" npy = "application/x-binary" xml = "application/xml" @@ -28,6 +29,7 @@ class ImageDriver(str, Enum): """Supported output GDAL drivers.""" jpeg = "JPEG" + jpg = "JPEG" png = "PNG" pngraw = "PNG" tif = "GTiff" @@ -42,7 +44,8 @@ class ImageType(str, Enum): png = "png" npy = "npy" tif = "tif" - jpeg = "jpg" + jpeg = "jpeg" + jpg = "jpg" jp2 = "jp2" webp = "webp" pngraw = "pngraw"