-- Native-size identity study, not a motion atlas. One scale across all views. local source=app.open(app.params.source) local pixels=Image(source.cels[1].image) for pixel in pixels:pixels() do local value=pixel() if app.pixelColor.rgbaA(value)>=192 then pixel(app.pixelColor.rgba(app.pixelColor.rgbaR(value),app.pixelColor.rgbaG(value),app.pixelColor.rgbaB(value),255)) else pixel(0) end end local boxes=dofile(app.params.boxes) assert(#boxes==4, 'Expected exactly four poses: south, west, east, north') local maxw,maxh=0,0 for _,box in ipairs(boxes) do maxw,maxh=math.max(maxw,box.w),math.max(maxh,box.h) end local factor=math.min(40/maxw,tonumber(app.params.height)/maxh) local sheet=Image(192,64,ColorMode.RGB) for i,box in ipairs(boxes) do local crop=Image(box.w,box.h,ColorMode.RGB) crop:drawImage(pixels,Point(-box.x,-box.y)) local tmp=Sprite(box.w,box.h,ColorMode.RGB) tmp.cels[1].image=crop local w,h=math.floor(box.w*factor+.5),math.floor(box.h*factor+.5) app.command.SpriteSize{ui=false,width=w,height=h,method='nearest-neighbor'} local anchor=math.floor((box.foot_x or box.w/2)*factor+.5) local frame=Image(48,64,ColorMode.RGB) frame:drawImage(tmp.cels[1].image,Point(24-anchor,61-h)) sheet:drawImage(frame,Point((i-1)*48,0)) tmp:close() end source:close() local out=Sprite(192,64,ColorMode.RGB) out.cels[1].image=sheet out:saveAs(app.params.output) out:close() print('Four static views exported; uniform scale '..factor)