-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
68 lines (65 loc) · 2.21 KB
/
main.py
File metadata and controls
68 lines (65 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from PIL import Image
import pillow_heif
import os
import sys
from art import *
art= text2art("Image Converter")
def main():
print(art)
print("1. HEIC to PNG")
print("2. HEIC to JPEG")
print("3. PNG to JPEG")
print("4. JPEG to PNG")
print("5. Exit")
userinput = input("Please Select an Option\n")
match userinput:
case "1":
im = input("Enter the image name (ex. Pic1): ")
img = "./" + im + ".heic"
heif_file = pillow_heif.read_heif(img)
image = Image.frombytes(
heif_file.mode,
heif_file.size,
heif_file.data,
"raw",
)
rename = input("Enter the new image name (ex. Pic1): ")
image.save("./" + rename + ".png", format("png"))
print("Image saved as " + rename + ".png")
main()
case "2":
im = input("Enter the image name (ex. Pic1): ")
img = "./" + im + ".heic"
heif_file = pillow_heif.read_heif(img)
image = Image.frombytes(
heif_file.mode,
heif_file.size,
heif_file.data,
"raw",
)
rename = input("Enter the new image name (ex. Pic1): ")
image.save("./" + rename + ".jpeg", format("jpeg"))
print("Image saved as " + rename + ".jpeg")
main()
case "3":
im = input("Enter the image name (ex. Pic1): ")
img = "./" + im + ".png"
image = Image.open(img)
rename = input("Enter the new image name (ex. Pic1): ")
image.save("./" + rename + ".jpeg", format("jpeg"))
print("Image saved as " + rename + ".jpeg")
main()
case "4":
im = input("Enter the image name (ex. Pic1): ")
img = "./" + im + ".jpeg"
image = Image.open(img)
rename = input("Enter the new image name (ex. Pic1): ")
image.save("./" + rename + ".png", format("png"))
print("Image saved as " + rename + ".png")
main()
case "5":
sys.exit()
case _:
print("Invalid Input")
main()
main()