I don’t know if it will be easy to reproduce, so I recorded a gif. I was experimenting with my own script for spritesheet composing, and at some point I discovered a strange behavior when the cel bounds are seemingly calculated incorrectly. The effect disappears if I touch the sprite with a brush, and returns if I undo the changes.
Using steam version.
Even if I just drag the image with the control held down, the size rulers show that the cel includes transparent pixels.
What is the sprite’s color mode? If the color mode is indexed, which palette swatch is the sprite’s transparent color?
For example, the image on the canvas above contains the index 2 color, which is not the sprite’s transparent color, index 0.
No, the color mode is RGB. Transparent pixels inside the cel actually have a color (from cel.image:getPixel(x, y) of zero.
Here is the file:
Dunno then. The image responds to shrinkBounds and app.command.CanvasSize with trimOutside
marked as true, as in the trimmed would be 13x11. Ctrl+clicking on the layer name selects its pixels properly. It doesn’t update its bounds from using the eraser, though, until an opaque pixel is removed.
Was the image generated or altered by a Lua script to begin with?
I don’t think so. There was a collection of frames imported from a spritesheet. I just deleted the others to narrow it down.
Hi there! Sometimes an image/cel bounds can be bigger (contain transparent pixels) when it’s loaded from a .png
and never touched. Then Aseprite shrink bounds when you start drawing. Not sure what you want to achieve with your script, but cel.bounds
will be the area where the cel.image
is located, and it might contain transparent borders in some cases (e.g. when you create a new image, the canvas contains one cel as big as the whole canvas).
I was trying to find the smallest rectangle that includes all the opaque (not fully transparent) pixels of the layer.
In that case you can use the Image:shrinkBounds() function as @behreandtjeremy said. Something like:
local rc = app.cel.image:shrinkBounds()
rc.origin = rc.origin + app.cel.bounds.origin
print(rc)