Skip to content

Commit

Permalink
add support for jpeg and jpg (#271)
Browse files Browse the repository at this point in the history
* add support for jpeg and jpg

* update changelog
  • Loading branch information
vincentsarago authored Mar 18, 2021
1 parent ab53427 commit 287201a
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
3 changes: 2 additions & 1 deletion docs/concepts/output_format.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down
10 changes: 8 additions & 2 deletions tests/routes/test_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]?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/[email protected]?url=https://myurl.com/cog.tif&nodata=0&bidx=1"
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/routes/test_mosaic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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")
5 changes: 4 additions & 1 deletion titiler/resources/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -28,6 +29,7 @@ class ImageDriver(str, Enum):
"""Supported output GDAL drivers."""

jpeg = "JPEG"
jpg = "JPEG"
png = "PNG"
pngraw = "PNG"
tif = "GTiff"
Expand All @@ -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"
Expand Down

0 comments on commit 287201a

Please sign in to comment.