mirror of
https://codeberg.org/vlw/pysheeter.git
synced 2025-09-14 03:33:40 +02:00
Package 1.0.6
Added pip package support
This commit is contained in:
parent
d174fe948a
commit
6288ab0e5c
11 changed files with 185 additions and 2 deletions
68
build/lib/pysheeter/PySheeter.py
Normal file
68
build/lib/pysheeter/PySheeter.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
import json
|
||||
from PIL import Image
|
||||
from pathlib import Path
|
||||
|
||||
# Create new sprite
|
||||
class Sprite:
|
||||
|
||||
def __init__(self,image,size):
|
||||
self.image = Image.open(image).convert("RGBA")
|
||||
|
||||
# Resize image to size[width,height] if nessesary
|
||||
if(self.image.width != size[0] or self.image.height != size[1]):
|
||||
self.resize(size)
|
||||
|
||||
# Resize image without maintaining aspect ratio
|
||||
def resize(self,size,resample=Image.LANCZOS):
|
||||
self.image = self.image.resize((size[0],size[1]),resample)
|
||||
|
||||
# --------------------------------
|
||||
|
||||
# Create new sheet of sprites
|
||||
class Sheet:
|
||||
|
||||
def __init__(self,folder = None):
|
||||
self.sprites = []
|
||||
|
||||
# Auto-import sprite folder
|
||||
if(folder):
|
||||
self.path = Path(folder).glob("**/*.png")
|
||||
self.sprites = [x for x in self.path]
|
||||
|
||||
print(f"Loaded {len(self.sprites)} sprites")
|
||||
|
||||
# Concatinate sprites vertically
|
||||
def concatV(self,size):
|
||||
sheet = Image.new("RGBA",(size[0],size[1] * len(self.sprites)))
|
||||
|
||||
for i, sprite in enumerate(self.sprites):
|
||||
sheet.paste(Sprite(sprite,size).image,(0,size[1] * i))
|
||||
|
||||
return sheet
|
||||
|
||||
# Concatinate sprites horizontally
|
||||
def concatH(self,size):
|
||||
sheet = Image.new("RGBA",(size[0] * len(self.sprites),size[1]))
|
||||
|
||||
for i, sprite in enumerate(self.sprites):
|
||||
sheet.paste(Sprite(sprite,size).image,(size[0] * i,0))
|
||||
|
||||
return sheet
|
||||
|
||||
# Add sprite by path
|
||||
def add(self,path):
|
||||
self.sprites.append(path)
|
||||
|
||||
# Remove sprite by path
|
||||
def remove(self,path):
|
||||
self.sprites.remove(path)
|
||||
|
||||
# Create and save spritesheet
|
||||
def put(self,dest,size,vertical = True):
|
||||
if(vertical):
|
||||
sheet = self.concatV(size)
|
||||
else:
|
||||
sheet = self.concatH(size)
|
||||
|
||||
sheet.save(dest)
|
||||
print(f"Saved spritesheet to '{dest}'")
|
0
build/lib/pysheeter/__init__.py
Normal file
0
build/lib/pysheeter/__init__.py
Normal file
BIN
dist/pysheeter-1.0.6-py3-none-any.whl
vendored
Normal file
BIN
dist/pysheeter-1.0.6-py3-none-any.whl
vendored
Normal file
Binary file not shown.
BIN
dist/pysheeter-1.0.6.tar.gz
vendored
Normal file
BIN
dist/pysheeter-1.0.6.tar.gz
vendored
Normal file
Binary file not shown.
104
pysheeter.egg-info/PKG-INFO
Normal file
104
pysheeter.egg-info/PKG-INFO
Normal file
|
@ -0,0 +1,104 @@
|
|||
Metadata-Version: 2.1
|
||||
Name: pysheeter
|
||||
Version: 1.0.6
|
||||
Summary: Lightweight Python-script to create sprite sheets from transparent PNGs with Pillow
|
||||
Home-page: https://github.com/VictorWesterlund/pysheeter
|
||||
Author: VicW
|
||||
Author-email: victor.vesterlund@gmail.com
|
||||
License: UNKNOWN
|
||||
Description: # PySheeter
|
||||
Lightweight Pillow Python-script to create and scale sprite sheets from PNGs in folders or individually
|
||||
|
||||
## Get started / Basic usage
|
||||
1. Download and install [Python 3](https://www.python.org/downloads/) for your architecture
|
||||
2. Install the latest version of PySheeter with [`pip3`](https://pypi.org/project/pysheeter-VicW/)
|
||||
```bash
|
||||
$ pip3 install pysheeter-VicW
|
||||
```
|
||||
### Sprite sheet from folder
|
||||
1. Import `Sheet` from `pysheeter`
|
||||
```python
|
||||
from pysheeter import Sheet
|
||||
```
|
||||
2. Initialize the class with a path to your PNG-folder
|
||||
```python
|
||||
spritesheet = pysheeter.Sheet("example/")
|
||||
```
|
||||
3. Create a sprite sheet with `put()`
|
||||
```python
|
||||
spritesheet.put("example_v1616.png",(16,16))
|
||||
# Creates a vertical spritesheet named 'example_v1616.png' with the dimensions 16x16px (scaled automatically)
|
||||
```
|
||||
|
||||
__Example usage:__
|
||||
```python
|
||||
# from 'example.py'
|
||||
from pysheeter import PySheeter
|
||||
|
||||
# Load sprites from 'example/'
|
||||
spritesheet = PySheeter.Sheet("example")
|
||||
|
||||
# Create a vertical spritesheet with the dimensions 16x16
|
||||
spritesheet.put("example_v1616.png",(16,16))
|
||||
|
||||
# Create a horizontal spritesheet with the dimensions 16x32
|
||||
spritesheet.put("example_h1632.png",(16,32),False)
|
||||
```
|
||||

|
||||

|
||||
### Sprite sheet from individual PNG-images
|
||||
1. Import `Sheet` from `pysheeter`
|
||||
```python
|
||||
from pysheeter import Sheet
|
||||
```
|
||||
2. Initialize the class without any arguments
|
||||
```python
|
||||
spritesheet = pysheeter.Sheet()
|
||||
```
|
||||
3. Add PNG-images with `add()`
|
||||
```python
|
||||
spritesheet.add("example/1.png")
|
||||
spritesheet.add("example/2.png")
|
||||
spritesheet.add("example/3.png")
|
||||
...
|
||||
```
|
||||
4. Remove PNG-images with `remove()`
|
||||
```python
|
||||
spritesheet.remove("example/2.png")
|
||||
```
|
||||
5. Create a sprite sheet with `put()`
|
||||
```python
|
||||
spritesheet.put("example_v1616.png",(16,16))
|
||||
# Creates a vertical spritesheet named 'example_v1616.png' with the dimensions 16x16px (scaled automatically)
|
||||
```
|
||||
|
||||
__Example usage:__
|
||||
```python
|
||||
from pysheeter import PySheeter
|
||||
|
||||
# Load sprites from 'example/'
|
||||
spritesheet = PySheeter.Sheet()
|
||||
|
||||
# Add PNG-images
|
||||
spritesheet.add("example/1.png")
|
||||
spritesheet.add("example/2.png")
|
||||
spritesheet.add("example/3.png")
|
||||
spritesheet.add("example/7.png")
|
||||
spritesheet.add("example/5.png")
|
||||
spritesheet.add("example/9.png")
|
||||
|
||||
# Create a vertical spritesheet with the dimensions 16x16
|
||||
spritesheet.put("example_v1616.png",(16,16))
|
||||
|
||||
# Create a horizontal spritesheet with the dimensions 16x32
|
||||
spritesheet.put("example_h1632.png",(16,32),False)
|
||||
```
|
||||

|
||||

|
||||
|
||||
Platform: UNKNOWN
|
||||
Classifier: Programming Language :: Python :: 3
|
||||
Classifier: License :: OSI Approved :: MIT License
|
||||
Classifier: Operating System :: OS Independent
|
||||
Requires-Python: >=3.6
|
||||
Description-Content-Type: text/markdown
|
9
pysheeter.egg-info/SOURCES.txt
Normal file
9
pysheeter.egg-info/SOURCES.txt
Normal file
|
@ -0,0 +1,9 @@
|
|||
README.md
|
||||
setup.py
|
||||
pysheeter/PySheeter.py
|
||||
pysheeter/__init__.py
|
||||
pysheeter.egg-info/PKG-INFO
|
||||
pysheeter.egg-info/SOURCES.txt
|
||||
pysheeter.egg-info/dependency_links.txt
|
||||
pysheeter.egg-info/requires.txt
|
||||
pysheeter.egg-info/top_level.txt
|
1
pysheeter.egg-info/dependency_links.txt
Normal file
1
pysheeter.egg-info/dependency_links.txt
Normal file
|
@ -0,0 +1 @@
|
|||
|
1
pysheeter.egg-info/requires.txt
Normal file
1
pysheeter.egg-info/requires.txt
Normal file
|
@ -0,0 +1 @@
|
|||
Pillow
|
1
pysheeter.egg-info/top_level.txt
Normal file
1
pysheeter.egg-info/top_level.txt
Normal file
|
@ -0,0 +1 @@
|
|||
pysheeter
|
|
@ -1 +0,0 @@
|
|||
import PySheeter
|
2
setup.py
2
setup.py
|
@ -5,7 +5,7 @@ with open("README.md","r") as fh:
|
|||
|
||||
setuptools.setup(
|
||||
name="pysheeter",
|
||||
version="1.0.5",
|
||||
version="1.0.6",
|
||||
author="VicW",
|
||||
author_email="victor.vesterlund@gmail.com",
|
||||
description="Lightweight Python-script to create sprite sheets from transparent PNGs with Pillow",
|
||||
|
|
Loading…
Add table
Reference in a new issue