How to save converted pictures to a downloadable ZIP file(Python)

Hello, please i need help with my code below:

  1. 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”

  1. There should be an option to upload and convert a minimum of 5 pictures, the same format or different formats doesn’t matter

  2. 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

  3. The script when run should bring up a prompt asking the user to upload the image file(s)

  4. 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

So, you’ve given us your homework assignment… what have you tried to make it work?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.