Skip to content

Commit

Permalink
convert miao to png
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel4-Scratch committed Aug 17, 2024
1 parent edebd01 commit 59b6844
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ Miao image can also conver through one parameter. If the given file path is a co
miao.exe <input.png>
```

## Convert Miao File to Png
Miao Image can convert a miao file back into an image. The larger the image, the longer it will take to convert.
```miao.exe png <input.miao> <output.png>```

### Alternate Method
Miao Image can also convert through two parameters. If the given file path is a miao file it will convert it. The output file will be located in the working directory with the same name as the input file but with the `.png` extension.
```miao.exe png <input.miao>```

## Display Miao File
Miao Image convert the miao file back into an image to display though a gui window.
The larger the image, the longer it will take to display.
Expand Down
28 changes: 28 additions & 0 deletions miao.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,27 @@ def save_image_data(image_path, output_path):
with open(output_path, "wb") as f:
f.write(compressed_image)

def miao_to_png(image_path, output_path):
with open(image_path, "rb") as f:
compressed_image = f.read()

image_data = zlibdecompress(compressed_image).decode('utf-8')

# Create a new image
width = len(image_data.split('\n')[0]) // 9
height = len(image_data.split('\n')) - 1
im = Image.new("RGBA", (width, height))
pix = im.load()

for y, row in enumerate(image_data.split('\n')):
if row:
for x in range(width):
hex_value = row[x*9:(x+1)*9]
rgba = tuple(int(hex_value[i:i+2], 16) for i in (1, 3, 5, 7))
pix[x, y] = rgba

im.save(output_path)

class ImageDisplayer:
def __init__(self, image_path=None):
self.image_path = image_path
Expand Down Expand Up @@ -175,6 +196,13 @@ if len(sys.argv) > 1:
if sys.argv[1] == "convert":
if os.path.isfile(sys.argv[2]):
save_image_data(sys.argv[2], sys.argv[3])
elif sys.argv[1] == "png":
if os.path.isfile(sys.argv[2]):
#check if arg 3 wasnt provided
if len(sys.argv) < 4:
miao_to_png(sys.argv[2], sys.argv[2].replace(".miao", ".png"))
else:
miao_to_png(sys.argv[2], sys.argv[3])
elif sys.argv[1] == "display":
if os.path.isfile(sys.argv[2]):
ImageDisplayer(sys.argv[2]).root.mainloop()
Expand Down

0 comments on commit 59b6844

Please sign in to comment.