feat: a ready sheet can carry the empty strips cut from its top and bottom, and prints without them
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 7m49s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m23s
All checks were successful
Build and deploy / Validate source (push) Successful in 7s
Build and deploy / Integration suite on a real stack (push) Successful in 7m49s
Build and deploy / Secret scan and release gate (push) Successful in 5s
Build and deploy / Publish images (push) Successful in 1m23s
Step 1 of trimming empty strips (Marcus, 2026-11-18): the server side. - ProductionSource has trim_top_cm and trim_bottom_cm (default 0); only a measured finished sheet may carry them, and length_cm is what is left, billed and printed. - The generator leaves those file rows out (whole decode and banded PNG reading), and the proportion check compares the art with what is left. A PDF with a cut, or a cut that does not match the file, goes to hand preparation. - The Prumo report says "Faixas vazias cortadas: N cm". The Site does not send the cut yet (step 2). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -226,6 +226,8 @@ class Source:
|
||||
|
||||
def __init__(self, path, name):
|
||||
self.path, self.name = path, name
|
||||
# File rows left out at the top and the bottom (trim()).
|
||||
self.cut = (0, 0)
|
||||
with open(path, 'rb') as handle:
|
||||
head = handle.read(1024)
|
||||
self.pdf = b'%PDF-' in head
|
||||
@@ -268,6 +270,23 @@ class Source:
|
||||
pass
|
||||
image.close()
|
||||
|
||||
def trim(self, spec):
|
||||
"""Leave out the empty strips the Site cut from a ready sheet's top and
|
||||
bottom (Marcus, 2026-11-18). From then on `size` is what is printed."""
|
||||
top_cm = Decimal(str(spec.get('trim_top_cm') or 0))
|
||||
bottom_cm = Decimal(str(spec.get('trim_bottom_cm') or 0))
|
||||
if not (top_cm or bottom_cm):
|
||||
return
|
||||
if self.pdf:
|
||||
raise Unsupported(f'"{self.name}": o corte das faixas vazias só vale para imagens')
|
||||
full_cm = Decimal(str(spec['length_cm'])) + top_cm + bottom_cm
|
||||
width, height = self.size
|
||||
top, bottom = round(height * top_cm / full_cm), round(height * bottom_cm / full_cm)
|
||||
if top + bottom >= height:
|
||||
raise Unsupported(f'"{self.name}": o corte das faixas vazias tiraria o arquivo inteiro')
|
||||
self.cut = (top, bottom)
|
||||
self.size = (width, height - top - bottom)
|
||||
|
||||
def decoded(self, width, height):
|
||||
"""The whole file at (width, height) px, upright, RGBA."""
|
||||
if self.pdf:
|
||||
@@ -325,7 +344,15 @@ class Piece:
|
||||
key = (id(self.source), self.rotation, self.mirrored, self.w, self.h)
|
||||
if key not in cache:
|
||||
upright = (self.h, self.w) if self.rotation in (90, 270) else (self.w, self.h)
|
||||
image = self.source.decoded(*upright)
|
||||
top, bottom = self.source.cut
|
||||
if top or bottom:
|
||||
# A trimmed sheet (never turned): the file at the piece's scale,
|
||||
# then the rows between the strips.
|
||||
scale = self.h / self.source.size[1]
|
||||
image = self.source.decoded(self.w, max(1, round((self.source.size[1] + top + bottom) * scale)))
|
||||
image = image.crop((0, round(top * scale), self.w, round(top * scale) + self.h))
|
||||
else:
|
||||
image = self.source.decoded(*upright)
|
||||
if self.mirrored:
|
||||
image = ImageOps.mirror(image)
|
||||
if self.rotation:
|
||||
@@ -349,10 +376,13 @@ class Piece:
|
||||
self.reader = PngRows(self.source.path)
|
||||
self.buffer, self.buffer_top = None, 0
|
||||
sw, sh = self.reader.width, self.reader.height
|
||||
per_row = sh / self.h
|
||||
# A trimmed sheet starts `skip` file rows down and stops `cut` rows short.
|
||||
skip, cut = self.source.cut
|
||||
per_row = (sh - skip - cut) / self.h
|
||||
# The source rows behind [a, b), with room for the filter on each side.
|
||||
margin = 0 if per_row == 1 and sw == self.w else math.ceil(3 * max(per_row, 1)) + 2
|
||||
want_top, want_bottom = max(0, math.floor(a * per_row) - margin), min(sh, math.ceil(b * per_row) + margin)
|
||||
want_top = max(0, math.floor(a * per_row) + skip - margin)
|
||||
want_bottom = min(sh, math.ceil(b * per_row) + skip + margin)
|
||||
while self.buffer_top + (self.buffer.height if self.buffer else 0) < want_bottom:
|
||||
band = rgba(self.reader.band(BAND_ROWS))
|
||||
if self.buffer is None:
|
||||
@@ -366,8 +396,8 @@ class Piece:
|
||||
self.buffer = self.buffer.crop((0, want_top - self.buffer_top, sw, self.buffer.height))
|
||||
self.buffer_top = want_top
|
||||
if per_row == 1 and sw == self.w:
|
||||
return self.buffer.crop((0, a - self.buffer_top, sw, b - self.buffer_top))
|
||||
box = (0, a * per_row - self.buffer_top, sw, b * per_row - self.buffer_top)
|
||||
return self.buffer.crop((0, a + skip - self.buffer_top, sw, b + skip - self.buffer_top))
|
||||
box = (0, a * per_row + skip - self.buffer_top, sw, b * per_row + skip - self.buffer_top)
|
||||
return self.buffer.resize((self.w, b - a), Image.LANCZOS, box=box)
|
||||
|
||||
def close(self):
|
||||
@@ -455,6 +485,8 @@ def render(item, files, out_dir, prefix, footer=None, part_cm=None, tiles=False,
|
||||
raise Unsupported('o item usa uma montagem antiga')
|
||||
sources = [Source(*files[index]) for index in range(len(production['sources']))]
|
||||
try:
|
||||
for spec, source in zip(production['sources'], sources):
|
||||
source.trim(spec)
|
||||
vector = {index for index, source in enumerate(sources) if source.pdf}
|
||||
lowest = check_layout(item, [source.size for source in sources], vector, proof=bool(limit_cm))
|
||||
width = px(production['film_width_cm'])
|
||||
|
||||
Reference in New Issue
Block a user