[object Object]

← back to Kravet Sheet Sync 2026 04 20

Fix: shrink Kravet images to <=2048px JPEG before upload (was raw 36MB print-master originalSource → filled 500GB Shopify cap)

c074c8e32a1cb731077c006811d045ff1dc4691d · 2026-07-30 07:29:49 -0700 · Steve Abrams

Files touched

Diff

commit c074c8e32a1cb731077c006811d045ff1dc4691d
Author: Steve Abrams <steve@designerwallcoverings.com>
Date:   Thu Jul 30 07:29:49 2026 -0700

    Fix: shrink Kravet images to <=2048px JPEG before upload (was raw 36MB print-master originalSource → filled 500GB Shopify cap)
---
 bulk_push_v1.py | 42 +++++++++++++++++++++++++++++-------------
 1 file changed, 29 insertions(+), 13 deletions(-)

diff --git a/bulk_push_v1.py b/bulk_push_v1.py
index 4064839..c2980e0 100644
--- a/bulk_push_v1.py
+++ b/bulk_push_v1.py
@@ -18,11 +18,32 @@ Pipeline per SKU:
 Run:
   python3 bulk_push_v1.py --limit 10
 """
-import argparse, json, re, subprocess, sys, time, urllib.request
+import argparse, json, os, re, subprocess, sys, time, urllib.request, base64, tempfile
 from concurrent.futures import ThreadPoolExecutor, as_completed
 
 TOKEN = os.environ.get('SHOPIFY_ADMIN_TOKEN','')
 SHOP  = 'designer-laboratory-sandbox.myshopify.com'
+REST_BASE = 'https://designer-laboratory-sandbox.myshopify.com/admin/api/2024-10'
+SHRINK_PY = os.path.expanduser('~/Projects/dw-image-shrink/shrink_master.py')
+
+def attach_shrunk(pid, url, alt, sku='img'):
+    """Download a (possibly huge) print-master, shrink to <=2048px JPEG q82, upload as a
+    Shopify image ATTACHMENT. Replaces the old originalSource:raw_url pattern that made
+    Shopify store 36MB PNG print-masters and filled the 500GB file cap (2026-07-30 fix)."""
+    numeric = str(pid).split('/')[-1]
+    src = tempfile.mktemp(suffix='.src'); out = tempfile.mktemp(suffix='.jpg')
+    try:
+        subprocess.run(['curl','-sL','-A','Mozilla/5.0','-e','https://www.kravet.com/', url, '-o', src], check=True)
+        subprocess.run(['python3', SHRINK_PY, '--in', src, '--out', out, '--max-edge','2048','--quality','82'], check=True)
+        b64 = base64.b64encode(open(out,'rb').read()).decode()
+        body = json.dumps({'image': {'attachment': b64, 'filename': f'{sku}.jpg', 'alt': alt}}).encode()
+        req = urllib.request.Request(f'{REST_BASE}/products/{numeric}/images.json', data=body, method='POST',
+              headers={'Content-Type':'application/json','X-Shopify-Access-Token':TOKEN})
+        urllib.request.urlopen(req, timeout=90).read()
+    finally:
+        for f in (src, out):
+            try: os.unlink(f)
+            except OSError: pass
 GQL   = f'https://{SHOP}/admin/api/2024-10/graphql.json'
 SSH   = ['ssh', 'root@45.61.58.125']
 NEW_ARRIVALS = 'gid://shopify/Collection/167327760435'
@@ -311,22 +332,17 @@ def push_one(it):
         "id": dvid, "optionValues": [{"optionName": "Title", "name": main_opt}]}]})
     gql(VARIANT_CREATE_STRATEGY, {"pid": pid, "vs": [sv], "st": "DEFAULT"})
 
-    # 5) Attach image
-    gql(MEDIA_CREATE, {"pid": pid, "m": [{
-        "originalSource": it["image_url"],
-        "mediaContentType": "IMAGE",
-        "alt": title,
-    }]})
+    # 5) Attach image — SHRUNK before upload (was originalSource:raw_url, which stored
+    #    36MB PNG print-masters and filled the 500GB Shopify file cap). 2026-07-30 fix.
+    _sku = it.get("mfr_sku", "img")
+    attach_shrunk(pid, it["image_url"], title, _sku)
     if it.get("full_repeat_url"):
         try:
-            gql(MEDIA_CREATE, {"pid": pid, "m": [{
-                "originalSource": it["full_repeat_url"].replace(" ", "%20"),
-                "mediaContentType": "IMAGE",
-                "alt": f"{title} — full pattern repeat",
-            }]})
+            attach_shrunk(pid, it["full_repeat_url"].replace(" ", "%20"),
+                          f"{title} — full pattern repeat", f"{_sku}_repeat")
         except Exception as e:
             print(f"  full_repeat skipped: {e}")
-    print(f"  image attached")
+    print(f"  image attached (shrunk <=2048px q82)")
 
     # 6) Metafields (chunked at 25)
     mfs = build_metafields(it, pid)

← 9f79453 auto-save: 2026-07-17T19:47:29 (1 files) — __pycache__/  ·  back to Kravet Sheet Sync 2026 04 20  ·  auto-save: 2026-07-30T07:45:45 (1 files) — __pycache__/bulk_ 2779d0d →