Уточнить проверку и доказательства ЛР 7
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
+6
-5
@@ -17,7 +17,7 @@ def fit(image, limit):
|
||||
return image.resize(size, Image.Resampling.LANCZOS)
|
||||
|
||||
|
||||
def convert(root):
|
||||
def convert(root, version):
|
||||
try:
|
||||
with Image.open(root / "source") as source:
|
||||
if source.width * source.height > MAX_PIXELS or source.format not in ("PNG", "JPEG"):
|
||||
@@ -27,10 +27,11 @@ def convert(root):
|
||||
rgb.paste(image, mask=image.getchannel("A"))
|
||||
except (UnidentifiedImageError, Image.DecompressionBombError, SyntaxError, OSError):
|
||||
return 2
|
||||
jpeg_quality, webp_quality = (85, 82) if version == 1 else (89, 84)
|
||||
outputs = [
|
||||
("thumbnail", fit(rgb, 256), "JPEG", "image/jpeg", 85),
|
||||
("crop", ImageOps.fit(rgb, (128, 128), Image.Resampling.LANCZOS), "JPEG", "image/jpeg", 85),
|
||||
("optimized", fit(rgb, 1280), "WEBP", "image/webp", 82),
|
||||
("thumbnail", fit(rgb, 256), "JPEG", "image/jpeg", jpeg_quality),
|
||||
("crop", ImageOps.fit(rgb, (128, 128), Image.Resampling.LANCZOS), "JPEG", "image/jpeg", jpeg_quality),
|
||||
("optimized", fit(rgb, 1280), "WEBP", "image/webp", webp_quality),
|
||||
]
|
||||
descriptors = []
|
||||
for name, image, format_name, mime, quality in outputs:
|
||||
@@ -42,4 +43,4 @@ def convert(root):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(convert(Path(sys.argv[1])))
|
||||
sys.exit(convert(Path(sys.argv[1]), int(sys.argv[2])))
|
||||
|
||||
Reference in New Issue
Block a user