Skip to content

Instantly share code, notes, and snippets.

@Stanko
Last active January 12, 2026 14:37
Show Gist options
  • Select an option

  • Save Stanko/ce28d550dd48500b658066372b3f9fdb to your computer and use it in GitHub Desktop.

Select an option

Save Stanko/ce28d550dd48500b658066372b3f9fdb to your computer and use it in GitHub Desktop.
-- Aseprite Script: Add 1px Padding to Tilemap
-- Takes a tilemap and creates a new file with 2x larger grid (1px padding per tile)
local sprite = app.activeSprite
if not sprite then
app.alert("No active sprite")
return
end
-- Get original sprite properties
local origWidth = sprite.width
local origHeight = sprite.height
local origGrid = sprite.gridBounds
local gridWidth = origGrid.width
local gridHeight = origGrid.height
-- Check if grid is defined
if gridWidth <= 0 or gridHeight <= 0 then
app.alert("No grid defined in the original sprite")
return
end
-- Calculate number of tiles
local tilesX = math.floor(origWidth / gridWidth)
local tilesY = math.floor(origHeight / gridHeight)
-- Calculate new dimensions with padding
local newGridWidth = gridWidth + 2
local newGridHeight = gridHeight + 2
local newWidth = tilesX * newGridWidth
local newHeight = tilesY * newGridHeight
-- Create new sprite
local newSprite = Sprite(newWidth, newHeight, sprite.colorMode)
newSprite.gridBounds = Rectangle(0, 0, newGridWidth, newGridHeight)
-- Copy palette
newSprite:setPalette(sprite.palettes[1])
-- Delete the default layer in new sprite
if #newSprite.layers > 0 then
newSprite:deleteLayer(newSprite.layers[1])
end
-- Process each layer
for i, layer in ipairs(sprite.layers) do
if layer.isImage then
-- Create corresponding layer in new sprite
local newLayer = newSprite:newLayer()
newLayer.name = layer.name
newLayer.opacity = layer.opacity
newLayer.blendMode = layer.blendMode
-- Get the cel from frame 1
local cel = layer:cel(1)
if cel then
local image = cel.image
local celPos = cel.position
local newImage = Image(newWidth, newHeight, sprite.colorMode)
-- Copy tiles with padding
for ty = 0, tilesY - 1 do
for tx = 0, tilesX - 1 do
-- Source position in original sprite coordinates
local srcX = tx * gridWidth
local srcY = ty * gridHeight
-- Convert to image coordinates (account for cel position)
local imgX = srcX - celPos.x
local imgY = srcY - celPos.y
-- Destination position in new image (with 1px padding offset)
local dstX = tx * newGridWidth + 1
local dstY = ty * newGridHeight + 1
-- Copy the tile
for y = 0, gridHeight - 1 do
for x = 0, gridWidth - 1 do
-- Check bounds to avoid reading outside image
if imgX + x >= 0 and imgX + x < image.width and
imgY + y >= 0 and imgY + y < image.height then
local pixel = image:getPixel(imgX + x, imgY + y)
newImage:putPixel(dstX + x, dstY + y, pixel)
end
end
end
end
end
-- Create cel in new sprite at origin
newSprite:newCel(newLayer, 1, newImage, Point(0, 0))
end
end
end
-- Refresh to show the new sprite
app.refresh()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment