# Image Sheet Exporter: working with modification to corona-imagesheet.lua file  

**URL:** <https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000>\
**Category:** TexturePacker\
**Created:** [March 22, 2012, 6:03am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000 "2012-03-22T06:03:58Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Darkmod](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@Darkmod](https://forums.solar2d.com/u/Darkmod)\
**Post date:** [March 22, 2012, 6:03am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/1 "2012-03-22T06:03:58Z")

</div>

Requires Texture packer ( 3.0.0b3 )

You need to edit your export Template //Program Files/TexturePacker/bin/exporters/corona-imagesheet/ corona-imagesheet.lua

You can modify this file to your own needs here is an example how i use it with two functions. “getSheet” , “getFrame”

## [lua]– – created with TexturePacker ([http://www.texturepacker.com](http://www.texturepacker.com))

– {{smartUpdateKey}}  
local V = {}  
local sheet =  
{  
frames = {  
{% for sprite in sprites %}  
{ x={{sprite.frameRect.x}}, y={{sprite.frameRect.y}}, width={{sprite.frameRect.width}}, height={{sprite.frameRect.height}} }, – {{sprite.trimmedName}}  
{% endfor %}  
},

sheetContentWidth = {{texture.size.width}},  
sheetContentHeight = {{texture.size.height}}  
}

local frameindex =  
{  
{% for sprite in sprites %}  
[’{{sprite.trimmedName}}’]= {{ forloop.counter }},  
{% endfor %}  
}  
local function getSheet() return sheet end  
local function getFrame() return frameindex end

V.getSheet = getSheet  
V.getFrame = getFrame

return V[/lua]

Example:  
[lua]local sheetInfo = require(“myExportedImageSheet”) – lua file that Texture packer published

local myImageSheet = graphics.newImageSheet( “ImageSheet.png”, sheetInfo.getSheet() ) – ImageSheet.png is the image Texture packer published

local myImage1 = display.newImage( myImageSheet , sheetInfo.getFrame()[“image\_name1”] )  
local myImage2 = display.newImage( myImageSheet , sheetInfo.getFrame()[“image\_name2”] ) [/lua]

cheers Darkmod  
lol: After looking at this it really should be “getIndex” and “getFrames” then nice thing is you can modify the export to your needs.

[import]uid: 7177 topic\_id: 23739 reply\_id: 323739[/import]

---

<div class="post-metadata">

**Author:** ![Danny](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@Danny](https://forums.solar2d.com/u/Danny)\
**Post date:** [March 22, 2012, 8:26am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/2 "2012-03-22T08:26:55Z")

</div>

Nice work, thanks for sharing [import]uid: 84637 topic\_id: 23739 reply\_id: 95467[/import]

---

<div class="post-metadata">

**Author:** ![punya.huxter](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/8edcca/32.png) [@punya.huxter](https://forums.solar2d.com/u/punya.huxter)\
**Post date:** [April 5, 2012, 1:25am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/3 "2012-04-05T01:25:41Z")

</div>

This looks like just what I need, but im having trouble finding where I can edit my exporters. Any idea how to do it on a Mac?  
Thanks. [import]uid: 65285 topic\_id: 23739 reply\_id: 98688[/import]

---

<div class="post-metadata">

**Author:** ![punya.huxter](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/p/8edcca/32.png) [@punya.huxter](https://forums.solar2d.com/u/punya.huxter)\
**Post date:** [April 10, 2012, 5:46pm UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/4 "2012-04-10T17:46:07Z")

</div>

Ah silly me, I needed to be using 3.0.0b3. All works fine now thanks Darkmod.

I sent a message to Andreas from Code’n’Web about updating Texture Packer. He will add this with the next update.  
[import]uid: 65285 topic\_id: 23739 reply\_id: 99935[/import]

---

<div class="post-metadata">

**Author:** ![Beloudest](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@Beloudest](https://forums.solar2d.com/u/Beloudest)\
**Post date:** [April 25, 2012, 1:04am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/5 "2012-04-25T01:04:42Z")

</div>

Im now using version 3.0.0b5, which does the above. Ive had some issues with sprites not aligning correctly. Could you help me out by letting me know what settings to use or not use when packing a sprite in texture packer? thx [import]uid: 118379 topic\_id: 23739 reply\_id: 103035[/import]

---

<div class="post-metadata">

**Author:** ![Darkmod](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/ea666f/32.png) [@Darkmod](https://forums.solar2d.com/u/Darkmod)\
**Post date:** [April 25, 2012, 10:30am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/6 "2012-04-25T10:30:41Z")

</div>

with the new build you will need too add size too sheetContent  
was \<\<  
sheetContentWidth = {{texture.width}},  
sheetContentHeight = {{texture.height}}  
now \<\<

sheetContentWidth = {{texture.size.width}},  
sheetContentHeight = {{texture.size.height}}

I updated the original post as well.

[import]uid: 7177 topic\_id: 23739 reply\_id: 103106[/import]

---

<div class="post-metadata">

**Author:** ![andreas.loew](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@andreas.loew](https://forums.solar2d.com/u/andreas.loew)\
**Post date:** [April 25, 2012, 11:43am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/7 "2012-04-25T11:43:37Z")

</div>

Hi,

I’ve just added an official exporter to TexturePacker which is quite similar to your solution.

To use it do the following:

```auto
local sheetInfo = require("spritesheet") -- lua file that Texture packer published  
  
local myImageSheet = graphics.newImageSheet( "spritesheet.png", sheetInfo:getSheet() )  
  
local myImage1 = display.newImage( myImageSheet , sheetInfo:getFrameIndex("drink"))  
local myImage2 = display.newImage( myImageSheet , sheetInfo:getFrameIndex("hamburger"))  
```

I moved the functions inside the data structure and added functions to get the frame indexes.

Cheers  
Andreas  
[import]uid: 9611 topic\_id: 23739 reply\_id: 103123[/import]

---

<div class="post-metadata">

**Author:** ![naveen\_pcs](https://forums.solar2d.com/user_avatar/forums.solar2d.com/naveen_pcs/32/224_2.png) [@naveen\_pcs](https://forums.solar2d.com/u/naveen_pcs)\
**Post date:** [April 27, 2012, 7:49am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/8 "2012-04-27T07:49:49Z")

</div>

Any chance on having it work with Dynamic Resolutions? I’m having problems because of the coordinates being used. See my post here:

[http://developer.anscamobile.com/forum/2012/04/26/new-sprite-api-dynamic-resolution-problem-video](http://developer.anscamobile.com/forum/2012/04/26/new-sprite-api-dynamic-resolution-problem-video)

Any solution to this?

EDIT: I found a fix to get Dynamic Res working! In texture packer, the “Border padding” and “Shape padding” default to “2”. That’s fine for regular resolution. When you want to make @2x res, you need to change both of those to “4” instead of 2. Hope this helps someone out! [import]uid: 51654 topic\_id: 23739 reply\_id: 103547[/import]

---

<div class="post-metadata">

**Author:** ![Beloudest](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@Beloudest](https://forums.solar2d.com/u/Beloudest)\
**Post date:** [April 29, 2012, 5:05am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/9 "2012-04-29T05:05:28Z")

</div>

@003naveen , nice one. that is what was eluding me. Makes sense. 🙂 [import]uid: 118379 topic\_id: 23739 reply\_id: 103845[/import]

---

<div class="post-metadata">

**Author:** ![danedwar](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/d/a88e4f/32.png) [@danedwar](https://forums.solar2d.com/u/danedwar)\
**Post date:** [May 3, 2012, 5:43am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/10 "2012-05-03T05:43:09Z")

</div>

I’ve modified the corona-imagesheet to use trimming that has been added to the new imagesheet API.

Just add sourceX, sourceY, sourceWidth, sourceHeight to the frames statement

```auto
frames = {  
 {% for sprite in sprites %}  
 { x={{sprite.frameRect.x}}, y={{sprite.frameRect.y}}, width={{sprite.frameRect.width}}, height={{sprite.frameRect.height}}, sourceX={{sprite.sourceRect.x}}, sourceY={{sprite.sourceRect.y}}, sourceWidth={{sprite.untrimmedSize.width}}, sourceHeight={{sprite.untrimmedSize.height}},}, -- {{sprite.trimmedName}}{% endfor %}  
 },  
```

You also need to turn on trimming in the exporter.xml

🙂 [import]uid: 77943 topic\_id: 23739 reply\_id: 104645[/import]

---

<div class="post-metadata">

**Author:** ![krystian6](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/k/22d042/32.png) [@krystian6](https://forums.solar2d.com/u/krystian6)\
**Post date:** [May 28, 2012, 12:25am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/11 "2012-05-28T00:25:11Z")

</div>

Hi Danedwar,

where did you get information about trimming from?  
I’ve searched through the whole docs and forums about this and couldn’t find anything.

Thanks,  
Krystian [import]uid: 109453 topic\_id: 23739 reply\_id: 109015[/import]

---

<div class="post-metadata">

**Author:** ![nml](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/n/41988e/32.png) [@nml](https://forums.solar2d.com/u/nml)\
**Post date:** [June 4, 2012, 7:23am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/12 "2012-06-04T07:23:16Z")

</div>

Hi! Danedwar can you explain a bit more about enabling trimming??  
I don’t have that option available in Texture Packer (currently runnning v 3.0.0b8), it appears faded out. Cropping is enabled, but i really need to trim.  
Thanks! [import]uid: 105206 topic\_id: 23739 reply\_id: 110125[/import]

---

<div class="post-metadata">

**Author:** ![andreas.loew](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@andreas.loew](https://forums.solar2d.com/u/andreas.loew)\
**Post date:** [June 4, 2012, 10:03am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/13 "2012-06-04T10:03:37Z")

</div>

If you want to enable it in the GUI again visit the exporter.xml and set

```auto
<supportstrimming>true</supportstrimming>  
```

cropping can be used with every exporter - since it simply resizes the original shape but trimming requires support from the target framework.

Does anybody have information how stable this API is? [import]uid: 9611 topic\_id: 23739 reply\_id: 110140[/import]

---

<div class="post-metadata">

**Author:** ![Juf\_Jannie](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@Juf\_Jannie](https://forums.solar2d.com/u/Juf_Jannie)\
**Post date:** [June 4, 2012, 10:08am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/14 "2012-06-04T10:08:22Z")

</div>

Well I got trimming to work fine for the SD images, but the HD images act all wonky. The coordinate system does not scale well it seems.  
Without trimming it works well. Don’t think they support dynamic scaling and trimming yet.  
[import]uid: 100901 topic\_id: 23739 reply\_id: 110141[/import]

---

<div class="post-metadata">

**Author:** ![andreas.loew](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/a/5fc32e/32.png) [@andreas.loew](https://forums.solar2d.com/u/andreas.loew)\
**Post date:** [June 4, 2012, 10:14am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/15 "2012-06-04T10:14:33Z")

</div>

I am working on that. The problem is currently that trimming might leave odd sized sprites which creates an incompatible layout.

That’s not a bug - TexturePacker tries to minimize memory usage - it just does not work well with the imagesheet api right now.

For now I would suggest

1. Disable trimming
2. Make sure your sprites are even sized
3. Use Padding=4 for hd
4. Use Padding=2 for sd

That should create identical sheets.  
[import]uid: 9611 topic\_id: 23739 reply\_id: 110143[/import]

---

<div class="post-metadata">

**Author:** ![nml](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/n/41988e/32.png) [@nml](https://forums.solar2d.com/u/nml)\
**Post date:** [June 5, 2012, 5:09am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/16 "2012-06-05T05:09:09Z")

</div>

where in my spritesheet.lua should i add the [blockcode] {% for sprite in sprites %}  
{ x={{sprite.frameRect.x}}, y={{sprite.frameRect.y}}, width={{sprite.frameRect.width}}, height={{sprite.frameRect.height}} }, – {{sprite.trimmedName}}  
{% endfor %} [/blockcode]  
code?

i have all the frames listed… should i add the code before or after? can anyone give me an example?  
[import]uid: 105206 topic\_id: 23739 reply\_id: 110270[/import]

---

<div class="post-metadata">

**Author:** ![krystian6](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/k/22d042/32.png) [@krystian6](https://forums.solar2d.com/u/krystian6)\
**Post date:** [June 5, 2012, 5:12am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/17 "2012-06-05T05:12:15Z")

</div>

Here’s mine:

```auto
local V = {}  
local sheet =  
{  
frames = {  
{% for sprite in allSprites %}  
{ x={{sprite.frameRect.x}}, y={{sprite.frameRect.y}}, width={{sprite.frameRect.width}}, height={{sprite.frameRect.height}} }, -- {{sprite.trimmedName}}  
{% endfor %}  
},  
  
sheetContentWidth = {{texture.size.width}},  
sheetContentHeight = {{texture.size.height}}  
}  
  
local frameindex =   
{  
{% for sprite in allSprites %}  
['{{sprite.fullName}}']= {{ forloop.counter }},  
{% endfor %}  
}  
  
V.spriteInfo = sheet  
V.frameInfo = frameindex  
  
return V  
```

works fine with aliases as well. [import]uid: 109453 topic\_id: 23739 reply\_id: 110274[/import]

---

<div class="post-metadata">

**Author:** ![nml](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/n/41988e/32.png) [@nml](https://forums.solar2d.com/u/nml)\
**Post date:** [June 5, 2012, 5:21am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/18 "2012-06-05T05:21:30Z")

</div>

Oh, ok thanks!! Now i understood!

EDIT: What’s the difference between that code and the one already inside texture packer?

corona-imageSheet.lua  
[blockcode]

## – – created with TexturePacker ([http://www.texturepacker.com](http://www.texturepacker.com))

## – {{smartUpdateKey}}

## – local sheetInfo = require(“myExportedImageSheet”) – lua file that Texture packer published

## – local myImageSheet = graphics.newImageSheet( “ImageSheet.png”, sheetInfo.getSheet() ) – ImageSheet.png is the image Texture packer published

## – local myImage1 = display.newImage( myImageSheet , sheetInfo.getFrameIndex(“image\_name1”)) – local myImage2 = display.newImage( myImageSheet , sheetInfo.getFrameIndex(“image\_name2”))

local SheetInfo = {}

SheetInfo.sheet =  
{  
frames = {  
{% for sprite in allSprites %}  
{ x={{sprite.frameRect.x}}, y={{sprite.frameRect.y}}, width={{sprite.frameRect.width}}, height={{sprite.frameRect.height}} }, – {{sprite.trimmedName}}{% endfor %}  
},

sheetContentWidth = {{texture.size.width}},  
sheetContentHeight = {{texture.size.height}}  
}

SheetInfo.frameIndex =  
{  
{% for sprite in allSprites %}  
["{{sprite.trimmedName}}"] = {{ forloop.counter }},{% endfor %}  
}

function SheetInfo:getSheet()  
return self.sheet;  
end

function SheetInfo:getFrameIndex(name)  
return self.frameIndex[name];  
end

return SheetInfo  
[/blockcode]  
[import]uid: 105206 topic\_id: 23739 reply\_id: 110275[/import]

---

<div class="post-metadata">

**Author:** ![krystian6](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/k/22d042/32.png) [@krystian6](https://forums.solar2d.com/u/krystian6)\
**Post date:** [June 5, 2012, 5:28am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/19 "2012-06-05T05:28:00Z")

</div>

hmmm

well I didn’t see the updated code in texture packer to be honest 🙂  
First off the filename is not trimmed in my version and the data structure returned by the script suits the way I handle imagesheets better.

Apart from that I don’t think there are any differences.  
[import]uid: 109453 topic\_id: 23739 reply\_id: 110277[/import]

---

<div class="post-metadata">

**Author:** ![Juf\_Jannie](https://forums.solar2d.com/letter_avatar_proxy/v4/letter/j/e47774/32.png) [@Juf\_Jannie](https://forums.solar2d.com/u/Juf_Jannie)\
**Post date:** [June 7, 2012, 5:03am UTC](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000/20 "2012-06-07T05:03:42Z")

</div>

Hi, Nice post,  
Why don’t you use the auto SD feature?

If your images allow it making them in a vector program is really handy. I create everything at 1.0 but export it at 2.0, that way they are always dividable by two.

Great info on the image sizes. [import]uid: 100901 topic\_id: 23739 reply\_id: 110642[/import]

[Next page](https://forums.solar2d.com/t/image-sheet-exporter-working-with-modification-to-corona-imagesheet-lua-file/301000.md?page=2)
