Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.
This is a very basic script I wrote to help myself split up one of them big icon sheets into individual files. After admiring its niftiness for a second, I realized someone else may get some use out of it as well, so here it is. I have also included the ability to combine multiple images into a single one.
Features
Extremely simple to use.
Splits large icon/sprite sheets up into uniform images, then saves them as individual files in a matter of seconds.
Can seperate any image into pieces of any size.
Can combine separate files into a single sheet.
Lightweight and fast
Screenshots
Turns this...
...into this...
...and vice-versa.
Script
[rgss]#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# Spritesheet Seperator/Combiner
# Author: ForeverZer0
# Date: 5.14.2011
# Version: 1.0
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
#
# Introduction:
# This is a very basic script I wrote to help myself split up one of them big
# icon sheets into individual files. After admiring its niftiness for a sec, I
# realized someone else may get some use out of it as well, so here it is.
#
# Features:
# - Extremely simple to use.
# - Splits large icon/sprite sheets up into uniform images, then saves them as
# individual files in a matter of seconds.
# - Can seperate any image into pieces of any size.
# - Combines many images of any size into one single file
# - Lightweight and fast
#
# Instructions:
# - Place script in new project or temporarily in an existing game anywhere
# before "Main"
# - Make any needed changes to the few configurations at the top of the script
# - Run the game
#
# Credits:
# - ForeverZer0, for the script
#
# Author's Notes:
# - Report bugs/issues at http://www.chaos-project.com
#
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# BEGIN CONFIGURATION
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
MODE = 1
# Select the mode to run in.
# 0 = Split Image
# 1 = Combine Images
FOLDER_NAME = 'Images'
# The folder name that the images will be placed into, or the folder where
# the images are contained that will be combined.
IMAGES_WIDE = 12
# The number of images that will be placed per row
FILENAME = 'combined'
# The output filename
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
# END CONFIGURATION
#=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
module Zlib
class Png_File < GzipWriter
#-------------------------------------------------------------------------------
def make_png(bitmap_Fx,mode)
@mode = mode
@bitmap_Fx = bitmap_Fx
self.write(make_header)
self.write(make_ihdr)
self.write(make_idat)
self.write(make_iend)
end
#-------------------------------------------------------------------------------
def make_header
return [0x89,0x50,0x4e,0x47,0x0d,0x0a,0x1a,0x0a].pack("C*")
end
#-------------------------------------------------------------------------------
def make_ihdr
ih_size = [13].pack("N")
ih_sign = "IHDR"
ih_width = [@bitmap_Fx.width].pack("N")
ih_height = [@bitmap_Fx.height].pack("N")
ih_bit_depth = [8].pack("C")
ih_color_type = [6].pack("C")
ih_compression_method = [0].pack("C")
ih_filter_method = [0].pack("C")
ih_interlace_method = [0].pack("C")
string = ih_sign + ih_width + ih_height + ih_bit_depth + ih_color_type +
ih_compression_method + ih_filter_method + ih_interlace_method
ih_crc = [Zlib.crc32(string)].pack("N")
return ih_size + string + ih_crc
end
#-------------------------------------------------------------------------------
def make_idat
header = "\x49\x44\x41\x54"
data = make_bitmap_data
data = Zlib::Deflate.deflate(data, 8)
crc = [Zlib.crc32(header + data)].pack("N")
size = [data.length].pack("N")
return size + header + data + crc
end
#-------------------------------------------------------------------------------
def make_bitmap_data1
w = @bitmap_Fx.width
h = @bitmap_Fx.height
data = []
for y in 0...h
data.push(0)
for x in 0...w
color = @bitmap_Fx.get_pixel(x, y)
red = color.red
green = color.green
blue = color.blue
alpha = color.alpha
data.push(red)
data.push(green)
data.push(blue)
data.push(alpha)
end
end
return data.pack("C*")
end
#-------------------------------------------------------------------------------
def make_bitmap_data
gz = Zlib::GzipWriter.open('hoge.gz')
t_Fx = 0
w = @bitmap_Fx.width
h = @bitmap_Fx.height
data = []
for y in 0...h
data.push(0)
for x in 0...w
t_Fx += 1
if t_Fx % 10000 == 0
Graphics.update
end
if t_Fx % 100000 == 0
s = data.pack("C*")
gz.write(s)
data.clear
end
color = @bitmap_Fx.get_pixel(x, y)
red = color.red
green = color.green
blue = color.blue
alpha = color.alpha
data.push(red)
data.push(green)
data.push(blue)
data.push(alpha)
end
end
s = data.pack("C*")
gz.write(s)
gz.close
data.clear
gz = Zlib::GzipReader.open('hoge.gz')
data = gz.read
gz.close
File.delete('hoge.gz')
return data
end
#-------------------------------------------------------------------------------
def make_iend
ie_size = [0].pack("N")
ie_sign = "IEND"
ie_crc = [Zlib.crc32(ie_sign)].pack("N")
return ie_size + ie_sign + ie_crc
end
end
end
def make_png(name="like", path="",mode=0)
make_dir(path) if path != ""
Zlib::Png_File.open("temp.gz") {|gz| gz.make_png(self, mode) }
Zlib::GzipReader.open("temp.gz") {|gz| $read = gz.read }
f = File.open(path + name + ".png","wb")
f.write($read)
f.close
File.delete('temp.gz')
end
#-------------------------------------------------------------------------------
def make_dir(path)
dir = path.split("/")
dir.each_index {|i|
unless dir == "."
add_dir = dir[0..i].join("/")
begin
Dir.mkdir(add_dir)
rescue
end
end
}
end
end
to Share - to copy, distribute and transmit the work
to Remix - to adapt the work
Under the following conditions:
Attribution. You must attribute the work in the manner specified by the author or licensor (but not in any way that suggests that they endorse you or your use of the work).
Noncommercial. You may not use this work for commercial purposes.
Share alike. If you alter, transform, or build upon this work, you may distribute the resulting work only under the same or similar license to this one.
- For any reuse or distribution, you must make clear to others the license terms of this work. The best way to do this is with a link to this web page.
- Any of the above conditions can be waived if you get permission from the copyright holder.
- Nothing in this license impairs or restricts the author's moral rights.