# Exporting indices

**URL:** <https://community.aseprite.org/t/exporting-indices/5295>\
**Category:** Help\
**Created:** [April 17, 2020, 10:36pm UTC](https://community.aseprite.org/t/exporting-indices/5295 "2020-04-17T22:36:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![zstuartp](https://community.aseprite.org/user_avatar/community.aseprite.org/zstuartp/32/4810_2.png) [@zstuartp](https://community.aseprite.org/u/zstuartp)\
**Post date:** [April 17, 2020, 10:36pm UTC](https://community.aseprite.org/t/exporting-indices/5295/1 "2020-04-17T22:36:11Z")

</div>

Is it possible to export just the index values from a sprite in indexed mode?

---

<div class="post-metadata">

**Author:** ![KashouC](https://community.aseprite.org/user_avatar/community.aseprite.org/kashouc/32/1404_2.png) [@KashouC](https://community.aseprite.org/u/KashouC)\
**Post date:** [April 17, 2020, 10:39pm UTC](https://community.aseprite.org/t/exporting-indices/5295/2 "2020-04-17T22:39:29Z")

</div>

Sounds like you’re just talking about saving the palette. In that case yes.

![image](https://community.aseprite.org/uploads/default/original/2X/d/db2d9e23cfdd039118c9279b7c95746cf4dd2085.png)

If not, then you’re gonna have to share a bit more of what you’re trying to do.

---

<div class="post-metadata">

**Author:** ![zstuartp](https://community.aseprite.org/user_avatar/community.aseprite.org/zstuartp/32/4810_2.png) [@zstuartp](https://community.aseprite.org/u/zstuartp)\
**Post date:** [April 17, 2020, 10:41pm UTC](https://community.aseprite.org/t/exporting-indices/5295/3 "2020-04-17T22:41:43Z")

</div>

I already saved the palette. What I need is to export the raw index values that the image is using to lookup colors in the palette.

---

<div class="post-metadata">

**Author:** ![zstuartp](https://community.aseprite.org/user_avatar/community.aseprite.org/zstuartp/32/4810_2.png) [@zstuartp](https://community.aseprite.org/u/zstuartp)\
**Post date:** [April 17, 2020, 11:41pm UTC](https://community.aseprite.org/t/exporting-indices/5295/4 "2020-04-17T23:41:43Z")

</div>

It feels like it should be basic functionality to be able export a raw indexed image format, even a just CSV or something is all I need. As far as I can tell, I am only able to export traditional image formats such as png, jpg, etc. I looked over the scripting API and I don’t see any obvious way to do what I need to do.

I really need this feature for my project, so if anyone has any ideas or can recommend another indexed-image editor that can actually export the raw data, please let me know.

---

<div class="post-metadata">

**Author:** ![zstuartp](https://community.aseprite.org/user_avatar/community.aseprite.org/zstuartp/32/4810_2.png) [@zstuartp](https://community.aseprite.org/u/zstuartp)\
**Post date:** [April 18, 2020, 2:43am UTC](https://community.aseprite.org/t/exporting-indices/5295/5 "2020-04-18T02:43:39Z")

</div>

I think I figured it out. I wrote an export script using the “Gameboy export” script posted here by boombuler as a guide. I just stripped out the gameboy assembly stuff and had it write the data directly to a file. Skimming over the output values it looks like it does give me the raw index values I wanted.

---

<div class="post-metadata">

**Author:** ![Strupf](https://community.aseprite.org/letter_avatar/strupf/32/6_22734026db12803ebb3e059622ac3534.png) [@Strupf](https://community.aseprite.org/u/Strupf)\
**Post date:** [July 20, 2020, 8:58pm UTC](https://community.aseprite.org/t/exporting-indices/5295/6 "2020-07-20T20:58:56Z")

</div>

Do you mind sharing your script? I’m looking for the exact same thing.

---

<div class="post-metadata">

**Author:** ![zstuartp](https://community.aseprite.org/user_avatar/community.aseprite.org/zstuartp/32/4810_2.png) [@zstuartp](https://community.aseprite.org/u/zstuartp)\
**Post date:** [July 20, 2020, 9:49pm UTC](https://community.aseprite.org/t/exporting-indices/5295/7 "2020-07-20T21:49:10Z")

</div>

Here you go:

```
local sprite = app.activeSprite

-- Check constraints
if sprite == nil then
  app.alert("No Sprite...")
  return
end
if sprite.colorMode ~= ColorMode.INDEXED then
  app.alert("Sprite needs to be indexed")
  return
end

local function getPaletteData(palette)
	local ncolors = #palette
	local res = string.format("%i\n", ncolors)

	for i=0, ncolors-1 do
		local color = palette:getColor(i)
		res = res .. string.format("%i %i %i %i\n", color.red, color.green, color.blue, color.alpha)		
	end

	return res
end

local function getIndexData(img, x, y, w, h)
	local res = ""
	for y = 0,h-1 do
		for x = 0, w-1 do
			px = img:getPixel(x, y)
			res = res .. string.format("%i ", px)
		end
		res = res .. "\n"
	end

	return res
end

local function exportFrame(frm)
	if frm == nil then
		frm = 1
	end

	local img = Image(sprite.spec)
	img:drawSprite(sprite, frm)
	
	io.write("Palette Indexed Picture\n")
	io.write("begin palette\n")
	io.write(getPaletteData(sprite.palettes[1]))
	io.write("end palette\n")
	io.write("begin indices\n")
	io.write(getIndexData(img, x, y, sprite.width, sprite.height))
	io.write("end indices\n")
end

local dlg = Dialog()
dlg:file{ id="exportFile",
          label="File",
          title="Gameboy-Assembler Export",
          open=false,
          save=true,
        --filename= p .. fn .. "pip",
          filetypes={"txt", "pip" }}
dlg:check{ id="onlyCurrentFrame",
           text="Export only current frame",
           selected=true }

dlg:button{ id="ok", text="OK" }
dlg:button{ id="cancel", text="Cancel" }
dlg:show()
local data = dlg.data
if data.ok then
	local f = io.open(data.exportFile, "w")
	io.output(f)

	if data.onlyCurrentFrame then
		exportFrame(app.activeFrame)
	else
	 	for i = 1,#sprite.frames do
	 		io.write(string.format(";Frame %d\n", i))
	 		exportFrame(i)
		end
	end

	io.close(f)
end

```

Just save it as a “.lua” file. When you are ready to export the index data, run the script and it should prompt you to save the file. It will save the palette information and the indices to a text file. Again, most of the credit goes to boombuler.

Hope it helps!

---

<div class="post-metadata">

**Author:** ![Strupf](https://community.aseprite.org/letter_avatar/strupf/32/6_22734026db12803ebb3e059622ac3534.png) [@Strupf](https://community.aseprite.org/u/Strupf)\
**Post date:** [July 21, 2020, 9:59am UTC](https://community.aseprite.org/t/exporting-indices/5295/8 "2020-07-21T09:59:35Z")

</div>

Works like a charm, thank you very much!

---

<div class="post-metadata">

**Author:** ![Plecra](https://community.aseprite.org/user_avatar/community.aseprite.org/plecra/32/8798_2.png) [@Plecra](https://community.aseprite.org/u/Plecra)\
**Post date:** [September 4, 2021, 10:41am UTC](https://community.aseprite.org/t/exporting-indices/5295/9 "2021-09-04T10:41:02Z")

</div>

Thanks for sharing that script! It really helped me understand how to use aseprite’s API. I needed to export my files in binary format, so I tweaked it a little to dump the index values directly.

I bundled it into an [extension](https://cdn.discordapp.com/attachments/527442731732041728/883664151745019984/export-raw.aseprite-exte) that adds a `File > Export Raw Pixels` menu if this would be useful for anyone else 🙂

---

<div class="post-metadata">

**Author:** ![Bubu](https://community.aseprite.org/user_avatar/community.aseprite.org/bubu/32/26502_2.png) [@Bubu](https://community.aseprite.org/u/Bubu)\
**Post date:** [June 22, 2026, 3:27pm UTC](https://community.aseprite.org/t/exporting-indices/5295/10 "2026-06-22T15:27:47Z")

</div>

As your extension isn’t available anymore, I created a new one. It can import and export raw indexed files.

[https://community.aseprite.org/t/extension-raw-index-tools/28473](https://community.aseprite.org/t/extension-raw-index-tools/28473)
