# SpineAtlas
Modify atlas data and export frames or convert other atlas-like data to spine atlas
## Installation
Install the latest version of `SpineAtlas` from PyPI:
```bash
pip install SpineAtlas
```
## Usage
# Opening and saving atlas
```python
from SpineAtlas import rbin, sline, SpineAtlas
data = rbin('1.atlas')
atlas_cls = SpineAtlas(data)
# version is bool, True is 4.x, False is 3.x
if atlas_cls.atlas.version:
# if atlas version is 4.x, save 3.x
atlas_cls.atlas.version = False
else:
# if atlas version is 3.x, save 4.x
atlas_cls.atlas.version = True
text = atlas_cls.atlas.ConvertText # List[str]
sline('1_mod.atlas', text)
```
# Modify the texture scaling of the atlas
```python
from SpineAtlas import rbin, sline, SpineAtlas, AtlasScale
data = rbin('1.atlas')
atlas_cls = SpineAtlas(data)
for i in atlas_cls.atlas.atlas:
# Get the width/height of png
png = rbin(i.png, 24)[16:]
pwidth, pheight = int.from_bytes(png[:4], byteorder='big'), int.from_bytes(png[4:], byteorder='big')
# Get the width/height of atlas
width, height = i.w, i.h
# Calculate scaling and modify
wscale, hscale = pwidth / width, pheight / height
AtlasScale(i, wscale, hscale)
# Reset the width/height of the texture in Atlas
i.w, i.h = pwidth, pheight
text = atlas_cls.atlas.ConvertText # List[str]
sline('1_scale.atlas', text)
```
# Export atlas frames
```python
from pathlib import Path
from PIL.Image import open as imgop
from SpineAtlas import rbin, SpineAtlas, AtlasImg
p = Path.cwd().joinpath('frames')
p.mkdir(parents=True, exist_ok=True)
data = rbin('1.atlas')
atlas_cls = SpineAtlas(data)
texs = {i.png:imgop(i.png) for i in atlas_cls.atlas.atlas} # set png dict
imgs = AtlasImg(texs, atlas_cls) # get frames
for k, v in imgs.items():
png = p.joinpath(f'{k}.png')
png.parent.mkdir(parents=True, exist_ok=True)
v.save(png.as_posix())
```
# Convert other formats to `Spine Atlas`
```python
from SpineAtlas import Atlas, Anchor, AtlasTex, AtlasFrame, ReOffset
'''
{
Texture:
Texture_Name: str
Texture_Wdith: int
Texture_Height: int
Frame:
[
[
Frame_Name: str
Cut_X: int
Cut_Y: int
Cut_Wdith: int
Cut_Height: int
Original_X: int
Original_Y: int
Original_Wdith: int
Original_Height: int
Rotate: int
],
...
]
}
'''
TextureDict = {...}
frames = []
for i in TextureDict['Frame']:
frames.append(AtlasFrame(i['Frame_Name'], i['Cut_X'], i['Cut_Y'], i['Cut_Wdith'], i['Cut_Height'], i['Original_X'], i['Original_Y'], i['Original_Wdith'], i['Original_Height'], i['Rotate']))
tex = TextureDict['Texture']
texture = AtlasTex(tex['Texture_Name'], tex['Texture_Wdith'], tex['Texture_Height'], frames=frames)
atlas = Atlas([texture])
text = atlas_cls.atlas.ConvertText # List[str]
sline('1.atlas', text)
```
# Recalculate the clipping anchor point
```python
from SpineAtlas import rbin, sline, Anchor, SpineAtlas, ReOffset
'''
class Anchor(IntEnum):
TOP_LEFT = 1
TOP_CENTER = 2
TOP_RIGHT = 3
CENTER_LEFT = 4
CENTER = 5
CENTER_RIGHT = 6
BOTTOM_LEFT = 7
BOTTOM_CENTER = 8
BOTTOM_RIGHT = 9
'''
data = rbin('1.atlas')
atlas_cls = SpineAtlas(data)
# The default anchor point for Spine Atlas clipping is the top left corner
atlas_cls.atlas.cutp = Anchor.BOTTOM_LEFT
ReOffset(atlas_cls.atlas) # Recalculate clipping X/Y starting from the upper left corner
text = atlas_cls.atlas.ConvertText # List[str]
sline('1_ReOffset.atlas', text)
```
# Recalculate the Offset anchor point
```python
from SpineAtlas import rbin, sline, Anchor, SpineAtlas, ReOffset
'''
class Anchor(IntEnum):
TOP_LEFT = 1
TOP_CENTER = 2
TOP_RIGHT = 3
CENTER_LEFT = 4
CENTER = 5
CENTER_RIGHT = 6
BOTTOM_LEFT = 7
BOTTOM_CENTER = 8
BOTTOM_RIGHT = 9
'''
data = rbin('1.atlas')
atlas_cls = SpineAtlas(data)
# The default anchor point for Spine Atlas Offset is the bottom left corner
atlas_cls.atlas.offp = Anchor.TOP_LEFT
ReOffset(atlas_cls.atlas) # Recalculate Offset X/Y starting from the bottom left corner
text = atlas_cls.atlas.ConvertText # List[str]
sline('1_ReOffset.atlas', text)
```
# # Convert image to premultiplied/non-premultiplied
```python
from PIL.Image import open as imgop
from SpineAtlas import ImgPremultiplied, ImgNonPremultiplied
img = imgop('1.png')
tex = ImgPremultiplied(img)
tex.save('1_premultiplied.png')
tex = ImgNonPremultiplied(img)
tex.save('1_non-premultiplied.png')
```
Raw data
{
"_id": null,
"home_page": "https://github.com/Rin-Wood/SpineAtlas",
"name": "SpineAtlas",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "spine, Python, atlas, SpineAtlas",
"author": "wood",
"author_email": "miraclerinwood@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c1/34/0ccce42990a765ad2dd63dbb4560b31848f6155bcceb3707997b3b637577/spineatlas-1.0.0.tar.gz",
"platform": null,
"description": "# SpineAtlas\nModify atlas data and export frames or convert other atlas-like data to spine atlas\n\n## Installation\nInstall the latest version of `SpineAtlas` from PyPI:\n\n```bash\npip install SpineAtlas\n```\n\n## Usage\n# Opening and saving atlas\n```python\nfrom SpineAtlas import rbin, sline, SpineAtlas\n\ndata = rbin('1.atlas')\natlas_cls = SpineAtlas(data)\n# version is bool, True is 4.x, False is 3.x\nif atlas_cls.atlas.version:\n # if atlas version is 4.x, save 3.x\n atlas_cls.atlas.version = False\nelse:\n # if atlas version is 3.x, save 4.x\n atlas_cls.atlas.version = True\ntext = atlas_cls.atlas.ConvertText # List[str]\nsline('1_mod.atlas', text)\n```\n# Modify the texture scaling of the atlas\n```python\nfrom SpineAtlas import rbin, sline, SpineAtlas, AtlasScale\n\ndata = rbin('1.atlas')\natlas_cls = SpineAtlas(data)\nfor i in atlas_cls.atlas.atlas:\n # Get the width/height of png\n png = rbin(i.png, 24)[16:]\n pwidth, pheight = int.from_bytes(png[:4], byteorder='big'), int.from_bytes(png[4:], byteorder='big')\n # Get the width/height of atlas\n width, height = i.w, i.h\n # Calculate scaling and modify\n wscale, hscale = pwidth / width, pheight / height\n AtlasScale(i, wscale, hscale)\n # Reset the width/height of the texture in Atlas\n i.w, i.h = pwidth, pheight\ntext = atlas_cls.atlas.ConvertText # List[str]\nsline('1_scale.atlas', text)\n```\n# Export atlas frames\n```python\nfrom pathlib import Path\nfrom PIL.Image import open as imgop\nfrom SpineAtlas import rbin, SpineAtlas, AtlasImg\n\np = Path.cwd().joinpath('frames')\np.mkdir(parents=True, exist_ok=True)\n\ndata = rbin('1.atlas')\natlas_cls = SpineAtlas(data)\ntexs = {i.png:imgop(i.png) for i in atlas_cls.atlas.atlas} # set png dict\nimgs = AtlasImg(texs, atlas_cls) # get frames\nfor k, v in imgs.items():\n png = p.joinpath(f'{k}.png')\n png.parent.mkdir(parents=True, exist_ok=True)\n v.save(png.as_posix())\n```\n# Convert other formats to `Spine Atlas`\n```python\nfrom SpineAtlas import Atlas, Anchor, AtlasTex, AtlasFrame, ReOffset\n\n'''\n{\nTexture:\n Texture_Name: str\n Texture_Wdith: int\n Texture_Height: int\n\t\nFrame:\n[\n [\n Frame_Name: str\n Cut_X: int\n Cut_Y: int\n Cut_Wdith: int\n Cut_Height: int\n Original_X: int\n Original_Y: int\n Original_Wdith: int\n Original_Height: int\n Rotate: int\n ],\n ...\n]\n}\n'''\nTextureDict = {...}\nframes = []\nfor i in TextureDict['Frame']:\n frames.append(AtlasFrame(i['Frame_Name'], i['Cut_X'], i['Cut_Y'], i['Cut_Wdith'], i['Cut_Height'], i['Original_X'], i['Original_Y'], i['Original_Wdith'], i['Original_Height'], i['Rotate']))\ntex = TextureDict['Texture']\ntexture = AtlasTex(tex['Texture_Name'], tex['Texture_Wdith'], tex['Texture_Height'], frames=frames)\natlas = Atlas([texture])\ntext = atlas_cls.atlas.ConvertText # List[str]\nsline('1.atlas', text)\n```\n# Recalculate the clipping anchor point\n```python\nfrom SpineAtlas import rbin, sline, Anchor, SpineAtlas, ReOffset\n\n'''\nclass Anchor(IntEnum):\n TOP_LEFT = 1\n TOP_CENTER = 2\n TOP_RIGHT = 3\n CENTER_LEFT = 4\n CENTER = 5\n CENTER_RIGHT = 6\n BOTTOM_LEFT = 7\n BOTTOM_CENTER = 8\n BOTTOM_RIGHT = 9\n'''\n\ndata = rbin('1.atlas')\natlas_cls = SpineAtlas(data)\n# The default anchor point for Spine Atlas clipping is the top left corner\natlas_cls.atlas.cutp = Anchor.BOTTOM_LEFT\nReOffset(atlas_cls.atlas) # Recalculate clipping X/Y starting from the upper left corner\ntext = atlas_cls.atlas.ConvertText # List[str]\nsline('1_ReOffset.atlas', text)\n```\n# Recalculate the Offset anchor point\n```python\nfrom SpineAtlas import rbin, sline, Anchor, SpineAtlas, ReOffset\n\n'''\nclass Anchor(IntEnum):\n TOP_LEFT = 1\n TOP_CENTER = 2\n TOP_RIGHT = 3\n CENTER_LEFT = 4\n CENTER = 5\n CENTER_RIGHT = 6\n BOTTOM_LEFT = 7\n BOTTOM_CENTER = 8\n BOTTOM_RIGHT = 9\n'''\n\ndata = rbin('1.atlas')\natlas_cls = SpineAtlas(data)\n# The default anchor point for Spine Atlas Offset is the bottom left corner\natlas_cls.atlas.offp = Anchor.TOP_LEFT\nReOffset(atlas_cls.atlas) # Recalculate Offset X/Y starting from the bottom left corner\ntext = atlas_cls.atlas.ConvertText # List[str]\nsline('1_ReOffset.atlas', text)\n```\n# # Convert image to premultiplied/non-premultiplied\n```python\nfrom PIL.Image import open as imgop\nfrom SpineAtlas import ImgPremultiplied, ImgNonPremultiplied\n\nimg = imgop('1.png')\n\ntex = ImgPremultiplied(img)\ntex.save('1_premultiplied.png')\n\ntex = ImgNonPremultiplied(img)\ntex.save('1_non-premultiplied.png')\n```\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python spine atlas parsing",
"version": "1.0.0",
"project_urls": {
"Homepage": "https://github.com/Rin-Wood/SpineAtlas"
},
"split_keywords": [
"spine",
" python",
" atlas",
" spineatlas"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "28ec44a4964473161f1aa8964b21ecb455d04f2ce8ee6ac13c6e6944a3a7f68a",
"md5": "26f48fa1cebc6c534a17209e142c72c2",
"sha256": "d0a8d8b5929ad76adb8854252c2754b05ba597d50fc5c25cd1e7bde21b64f69b"
},
"downloads": -1,
"filename": "SpineAtlas-1.0.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "26f48fa1cebc6c534a17209e142c72c2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 7598,
"upload_time": "2025-02-01T04:35:52",
"upload_time_iso_8601": "2025-02-01T04:35:52.904633Z",
"url": "https://files.pythonhosted.org/packages/28/ec/44a4964473161f1aa8964b21ecb455d04f2ce8ee6ac13c6e6944a3a7f68a/SpineAtlas-1.0.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c1340ccce42990a765ad2dd63dbb4560b31848f6155bcceb3707997b3b637577",
"md5": "5d4c1bcfde19a20cedd004964f232f4e",
"sha256": "30f0e441c9e04267db9f4c560799913142b3b3482755a3d482a69efb424e1195"
},
"downloads": -1,
"filename": "spineatlas-1.0.0.tar.gz",
"has_sig": false,
"md5_digest": "5d4c1bcfde19a20cedd004964f232f4e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 7669,
"upload_time": "2025-02-01T04:35:56",
"upload_time_iso_8601": "2025-02-01T04:35:56.773626Z",
"url": "https://files.pythonhosted.org/packages/c1/34/0ccce42990a765ad2dd63dbb4560b31848f6155bcceb3707997b3b637577/spineatlas-1.0.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-02-01 04:35:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "Rin-Wood",
"github_project": "SpineAtlas",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "spineatlas"
}