Hello, please i need help with my code below:
- To be able to accept these file extensions (strings) representing formats:
“JPG”, “JPEG”, “jpg”, “jpeg”, “png”, “PNG”, “bmp”, “BMP”, “gif”, “GIF”, “tiff”, “TIFF”, “webp”, “WEBP”
If the uploaded file doesn’t match any of the above it throw “Error”
-
There should be an option to upload and convert a minimum of 5 pictures, the same format or different formats doesn’t matter
-
Also, there is a need to collect all the image files uploaded and converted with the HTML code generated and put them in a zip folder all together for download
-
The script when run should bring up a prompt asking the user to upload the image file(s)
-
After conversion, it should ask the user to download the files and ask for a directory to save it. Thank you so much
MY CODE BELOW IT WORKS, BUT JUST NEED TO ADD ADDITIONAL FUNCTIONALITIES PROPERLY
#Import python Pillow library
from PIL import Image
#Import aspose words for python for creating html text
import aspose.words as aw
#Specify icon sizes to convert and download as .ico 3 sizes
icon_sizes = [(16, 16), (24, 24), (32, 32)]
#There is need to automatically accept different file formats such as"jpg", "jpeg", "png", "bmp", "gif", "tiff", "webp"}
#So that if there is an attempt to upload something else it show error
ALLOWED_EXTENSIONS = {"jpg", "jpeg", "png", "bmp", "gif", "tiff", "webp"}
# A function to check if the file is allowed here
#This is where the actual conversion happens
image = Image.open('pix.PNG')
fileoutpath = 'Favicon.ico'
for size in icon_sizes:
print(size[0])
fileoutname = fileoutpath + str(size[0]) + ".ico"
new_image = image.resize(size)
new_image.save(fileoutname)
#Returns the converted icon with a new filename + one more size
new_logo_ico_filename = fileoutpath + "128.ico"
new_logo_ico = image.resize((128, 128))
new_logo_ico.save(new_logo_ico_filename, format="ICO", quality=90)
#Below code converts the upload/targetted image to HTML code
#But i need a way to pass in the original image instead of manually doing so
doc = aw.Document()
builder = aw.DocumentBuilder(doc)
builder.insert_image("pix.PNG")
doc.save("Output.html")
#NOTE:
#Before running the above code loclly, make sure to:
#1 Install .NET Extension pack as VSCode extension
#2 Install Pillow using pip install pillow on your VSCode terminal
#3 Install aspose.words using pip install aspose.words on your VSCode terminal