Lua script's image size does not match actual image size

I have a simple 16x24 indexed sprite. But when I output the sprite’s size in Lua (app.activeCel.image.width/height), the script shows the width as 13px, not 16.

I noticed that when I hold the Cmd key, I see a little rectangle around my sprite that is only 13px. I don’t know what that is, but that might be why the script is reporting 13px as the width.

How can I get the “full” sprite’s pixels in the script?

You’re looking at the cel size (app.activeCel), cels are the subset of a sprite that exists in a particular frame/layer combination. You should be looking at the sprite size (app.activeSprite).

1 Like

Thanks! I would also like to view the individual pixels, but I only know how to get the pixels from the cel. Is there a way to directly access the pixels from the sprite?

Edit: when I do cel.image.getPixels() it returns the smaller subset size; I’m hoping there’s some way to get all the pixels from the full sprite.

BTW I was able to hack around my issue by looping over the entire sprite’s width/height and using image.getPixel if a given w/h was inside of the cel’s bounds and just assuming the transparent color if outside the cel’s bounds.

This works but it would be preferable to have direct access to a sprite’s pixels without considering cels. This was confusing for me because I didn’t even know what a cel was.

sadly, i don’t think there is a direct way to get all the pixels in whole sprite area - even on single layer - independently. it seems like there’s only image tied to cel and has it’s own position and boundaries. however, your assumption that everything outside image rectangle is transparent colour is correct. i agree, it’s not very handy.

1 Like

I have found a workaround.
Yes, if there are transparent pixels around the canvas, the image or sprite will be different than the canvas.

The code bellow will create an image and fill with the active cel image at the origin.
So the pixel at the coord 0,0 will be the same from the canvas.

    local srcImage = Image(cel.bounds.x + cel.bounds.width, cel.bounds.y + cel.bounds.height)
    srcImage:drawImage(cel.image, Point(cel.bounds.x, cel.bounds.y))