feat: the print file is a 300 DPI PNG, in parts of up to 15 m (item 13)
All checks were successful
Build and deploy / Validate source (push) Successful in 9s
Build and deploy / Integration suite on a real stack (push) Successful in 4m55s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m27s
All checks were successful
Build and deploy / Validate source (push) Successful in 9s
Build and deploy / Integration suite on a real stack (push) Successful in 4m55s
Build and deploy / Secret scan and release gate (push) Successful in 6s
Build and deploy / Publish images (push) Successful in 1m27s
FlexiPRINT's Spot OK 1 makes the white from transparency and reads it reliably only from a PNG (Dropstar's third round, item 13): each order item is now DTF-N-item-I.png, 300 DPI, RGBA on a transparent background, with its footer; a film over 15 m leaves as DTF-N-item-I-pK.png parts, each with "Parte K/N" in its footer, cut between pieces of loose art when it can be. app/printpng.py never holds a whole sheet: the film is composed and written in bands. Pillow encodes each band (it picks the PNG filters) and one zlib stream takes them; a long PNG sheet is read band by band by wrapping its compressed rows as small PNGs; a PDF page is drawn band by band at 300 DPI by PDFium (pypdfium2, a self-contained wheel); loose art is turned and scaled once. A 57 x 220 cm sheet peaks at 191 MB, a 15 m film at 279 MB. The parts of an item are dtf_local.print_parts (print_files.upload_id stays the first); the board, the final approval, the folders and the cleanup see every part, and the Kanban approves and downloads them all. A large PNG or PDF is now generated like any other; only other large formats go to hand preparation, and the original no longer stands in as the print file. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -9,7 +9,6 @@ Kanban until someone records what was done.
|
||||
Run inside the API container (it needs Pillow): python -m tests.print_file_test
|
||||
"""
|
||||
import io
|
||||
import re
|
||||
import time
|
||||
from urllib.request import urlopen
|
||||
from uuid import uuid4
|
||||
@@ -19,7 +18,19 @@ from PIL import Image
|
||||
from tests.payment_test import deliver
|
||||
from tests.smoke_test import Client, approved_quote as approval, upload_bytes
|
||||
|
||||
PT_PER_CM = 72 / 2.54
|
||||
PX_PER_CM = 300 / 2.54
|
||||
|
||||
|
||||
def px(cm):
|
||||
return int(round(cm * PX_PER_CM))
|
||||
|
||||
|
||||
def download_png(client, upload_id):
|
||||
link = client.call('/operator/uploads/' + str(upload_id) + '/download', operator=True)
|
||||
with urlopen(link['url'], timeout=30) as response:
|
||||
image = Image.open(io.BytesIO(response.read()))
|
||||
assert image.format == 'PNG' and image.mode == 'RGBA', (image.format, image.mode)
|
||||
return image
|
||||
CUSTOMER = {'cnpj': '11222333000181', 'zap': '11999999999', 'mail': 'print-test@example.test'}
|
||||
|
||||
|
||||
@@ -82,15 +93,16 @@ def run():
|
||||
order = paid_order(client, loose_item(uid))
|
||||
order, row = wait_print(client, order['id'], 'ready')
|
||||
assert row['detail']['placements'] == 2 and row['detail']['min_dpi'] == round(600 / (20 / 2.54))
|
||||
link = client.call('/operator/uploads/' + str(row['upload_id']) + '/download', operator=True)
|
||||
with urlopen(link['url'], timeout=30) as response:
|
||||
pdf = response.read()
|
||||
assert pdf.startswith(b'%PDF-') and pdf.rstrip().endswith(b'%%EOF')
|
||||
width, height = map(float, re.search(rb'/MediaBox \[0 0 ([\d.]+) ([\d.]+)\]', pdf).groups())
|
||||
# The layout's 10 cm and the 1,5 cm footer band, outside the billed length.
|
||||
assert abs(width - 57 * PT_PER_CM) < 0.01 and abs(height - 11.5 * PT_PER_CM) < 0.01, (width, height)
|
||||
# A 300 DPI PNG on a transparent background (item 13): the layout's 10 cm
|
||||
# and the 1,5 cm footer band, outside the billed length.
|
||||
film = download_png(client, row['upload_id'])
|
||||
assert film.size == (px(57), px(10) + px(1.5)), film.size
|
||||
assert [p['name'] for p in row['parts']] == ['DTF-%d-item-1.png' % order['number']], row['parts']
|
||||
for copy in range(2):
|
||||
assert film.getpixel((px(20 * copy + 10), px(5))) == (220, 30, 60, 255), copy
|
||||
assert film.getpixel((px(50), px(5)))[3] == 0
|
||||
assert row['detail']['footer'].startswith('DROPSTAR · Pedido DTF-%d · Item 1/1 · ' % order['number']), row['detail']
|
||||
print('PASS: paid order generated a 57 x 10 cm print file with both copies and its footer')
|
||||
print('PASS: paid order generated a 57 x 10 cm PNG print file with both copies and its footer')
|
||||
|
||||
# The automatic folder, downloading on arrival, gets the generated file
|
||||
# before anyone approves it; at the queue only, it does not.
|
||||
@@ -140,16 +152,15 @@ def run():
|
||||
'note': 'again'}, operator=True, expected=409)
|
||||
print('PASS: generated file approved as final without re-uploading; order queued for printing')
|
||||
|
||||
# A single-page PDF is placed as a vector form, not rasterised.
|
||||
# A single-page PDF is drawn from its vectors at 300 DPI.
|
||||
pdf_upload = upload_bytes(client, artwork('PDF'), name='LOCAL-PRINT-TEST.pdf')
|
||||
pdf_order = paid_order(client, loose_item(pdf_upload))
|
||||
_, pdf_row = wait_print(client, pdf_order['id'], 'ready')
|
||||
assert pdf_row['detail']['vector_sources'] == 1 and pdf_row['detail']['min_dpi'] is None, pdf_row
|
||||
link = client.call('/operator/uploads/' + str(pdf_row['upload_id']) + '/download', operator=True)
|
||||
with urlopen(link['url'], timeout=30) as response:
|
||||
generated = response.read()
|
||||
assert b'/Subtype /Form' in generated or b'/Subtype/Form' in generated
|
||||
print('PASS: PDF artwork generated as a vector print file')
|
||||
drawn = download_png(client, pdf_row['upload_id'])
|
||||
red = drawn.getpixel((px(10), px(5)))
|
||||
assert red[3] == 255 and red[0] > 200 and red[1] < 60, red
|
||||
print('PASS: PDF artwork drawn into the PNG print file at 300 DPI')
|
||||
|
||||
# A customer cannot see or reuse another order's generated file.
|
||||
other = Client()
|
||||
|
||||
Reference in New Issue
Block a user