From dab4a0600c77675ccd8553f7462923c25dae3a26 Mon Sep 17 00:00:00 2001 From: Russiankryt Date: Thu, 3 Dec 2026 17:25:39 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D1=82=D0=BE=D1=87=D0=BD=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80=D0=BA=D1=83=20?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=BE=D0=BA=D0=B0=D0=B7=D0=B0=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D1=8C=D1=81=D1=82=D0=B2=D0=B0=20=D0=9B=D0=A0=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pipeline.py | 6 +++--- src/variants.py | 11 ++++++----- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/pipeline.py b/src/pipeline.py index 65f1bad0..15fd09dd 100644 --- a/src/pipeline.py +++ b/src/pipeline.py @@ -116,12 +116,12 @@ def claim(store, message): return job -def encode_images(original): +def encode_images(original, version): with tempfile.TemporaryDirectory(prefix="messenger-image-") as name: root = Path(name) (root / "source").write_bytes(original) result = subprocess.run( - [sys.executable, "-m", "variants", str(root)], check=False, + [sys.executable, "-m", "variants", str(root), str(version)], check=False, timeout=CHILD_TIMEOUT, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, ) if result.returncode == 2: @@ -136,7 +136,7 @@ def try_publish(store, objects, job): attachment_id, version = job["attachment_id"], job["pipeline_version"] with tm.span("s3.staging.get", tm.SpanKind.CLIENT): original = objects.get(objects.key(attachment_id, "staging")) - processed = encode_images(original) + processed = encode_images(original, version) with store.pool.connection() as connection: current = connection.execute(""" SELECT j.attempt, j.state, a.pipeline_version, diff --git a/src/variants.py b/src/variants.py index 3061bdaa..d8a6d15f 100644 --- a/src/variants.py +++ b/src/variants.py @@ -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])))