local sprite=app.open(app.params.source) local fw,fh=tonumber(app.params.width),tonumber(app.params.height) local img=sprite.cels[1].image local a,b,c,d=img.width,img.height,-1,-1 for p in img:pixels() do local v=p() if app.pixelColor.rgbaA(v)>=192 then p(app.pixelColor.rgba(app.pixelColor.rgbaR(v),app.pixelColor.rgbaG(v),app.pixelColor.rgbaB(v),255)) a,b,c,d=math.min(a,p.x),math.min(b,p.y),math.max(c,p.x),math.max(d,p.y) else p(0) end end assert(c>=a and d>=b) sprite:crop(Rectangle(a,b,c-a+1,d-b+1)) local factor=math.min((fw-4)/sprite.width,(fh-4)/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((fw-w)/2),-(fh-2-h),fw,fh)) sprite:saveAs(app.params.output) sprite:close()