local sprite=app.open(app.params.source) local cel=sprite.cels[1] local img=cel.image local x0,y0,x1,y1=img.width,img.height,-1,-1 for pixel in img:pixels() do local c=pixel() if app.pixelColor.rgbaA(c)>=192 then pixel(app.pixelColor.rgba(app.pixelColor.rgbaR(c),app.pixelColor.rgbaG(c),app.pixelColor.rgbaB(c),255)) x0,y0,x1,y1=math.min(x0,pixel.x),math.min(y0,pixel.y),math.max(x1,pixel.x),math.max(y1,pixel.y) else pixel(0) end end assert(x1>=x0 and y1>=y0) sprite:crop(Rectangle(x0,y0,x1-x0+1,y1-y0+1)) local factor=math.min(156/sprite.width,188/sprite.height) local w,h=math.floor(sprite.width*factor+0.5),math.floor(sprite.height*factor+0.5) app.command.SpriteSize{ui=false,width=w,height=h,method='nearest-neighbor'} sprite:crop(Rectangle(-math.floor((160-w)/2),-(192-h),160,192)) sprite:saveAs(app.params.output) sprite:close()