-
Notifications
You must be signed in to change notification settings - Fork 108
/
profiles.py
63 lines (40 loc) · 1.53 KB
/
profiles.py
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
63
"""Image file profiles."""
from collections import UserDict
from rasterio.profiles import Profile # type: ignore
class JPEGProfile(Profile):
"""JPEG creation options ref: https://www.gdal.org/frmt_jpeg.html."""
defaults = {"quality": 85}
class PNGProfile(Profile):
"""PNG creation options ref: https://www.gdal.org/frmt_png.html."""
defaults = {"zlevel": 6}
class PNGRAWProfile(Profile):
"""PNG creation options ref: https://www.gdal.org/frmt_png.html."""
defaults = {"zlevel": 1}
class WEBPProfile(Profile):
"""WEBP creation options ref: https://www.gdal.org/frmt_webp.html."""
defaults = {"quality": 75, "lossless": False}
class ImagesProfiles(UserDict):
"""GDAL Image creation options.
ref: https://github.com/mapnik/mapnik/wiki/Image-IO#default-output-details.
"""
def __init__(self):
"""Initialize ImagesProfiles dict."""
self.data = {}
self.data.update(
{
"jpeg": JPEGProfile(),
"jpg": JPEGProfile(),
"png": PNGProfile(),
"pngraw": PNGRAWProfile(),
"webp": WEBPProfile(),
}
)
def get(self, key, default=None):
"""Like normal item access but return a copy of the key."""
if key in (self.keys()):
return self.data[key].copy()
return default
def __getitem__(self, key):
"""Like normal item access but return a copy of the key."""
return self.data[key].copy()
img_profiles = ImagesProfiles()