HugoBDesigner wrote:A code I wrote to convert frames to quads (a new image in quad format)!
Neat idea! Here's an IMHO cleaner and more efficient version. Instead of copying each pixel, use
ImageData:paste() instead.
Still, this is something that should probably better be done using a general purpose graphics package, instead of LÖVE. The restrictions of
love.filesystem mean you have to put the script in a love package and name it
main.lua, copy the image files in a subdirectory, run it and then get the output file from the save directory somewhere buried in
~/.local/share or similar. But it does work
Code: Select all
love.filesystem.setIdentity("maketilestrip")
local folder = arg[2]
local width = 0
local height = 0
local images = {}
local files = love.filesystem.getDirectoryItems(folder)
table.sort(files)
for _, file in ipairs(files) do
if string.sub(file, -4, -1) == ".png" then
local image = love.image.newImageData(folder .. "/" .. file)
local w, h = image:getDimensions()
images[#images+1] = {image, width, w, h}
width = width + w
height = math.max(height, h)
end
end
if #images ~= 0 then
local newimage = love.image.newImageData(width, height)
for _, image in ipairs(images) do
image, x, w, h = unpack(image)
newimage:paste(image, x, height - h, 0, 0, w, h)
end
print(("Writing output to '%s/%s.png'..."):format(
love.filesystem.getSaveDirectory():gsub('//', '/'), folder))
newimage:encode(folder .. ".png")
end
love.event.quit()