The height of images on Shopee and Lazada is different from the e-commerce site. Even though Shopee and Lazada do help to adjust the image dimensions within their site, at times, the product does not become centered anymore. Before this solution, the user would have to edit each image one by one. This is time-consuming.
I automated the process of reducing file size. I used an online provided solution to compress images called Tinify. This greatly reduces the image file size, optimising the website speed.
https://github.com/cnovel/TinifyInFolder
https://tinypng.com/developers/reference
Also, made a simple program to edit the desired dimensions for a folder of different images. For dimensions, I created two scripts to adjust just the width and height respectively. Users would just take the images they wanted to edit and add them to the “ImgResizing” folder. Then based on what they wanted to adjust, they would double click on ImageDimensions(Height).py or ImageDimensions(Width).py. A popup would show. Just enter the size desired in Pixels. The script will run and all the images in the folder will be adjusted.
import PIL
import os
import os.path
from PIL import Image
import tkinter as tk
from tkinter import simpledialog
#Opening PopUp
ROOT = tk.Tk()
ROOT.withdraw()
# the input dialog
USER_INP = simpledialog.askstring(title="Image Resizing", prompt="Please enter either 800 or 1000. For your desired size")
MsgBox = USER_INP
#Image Editing based on Height
#Maintains Ratio
def ExitApplication(baseheight):
f = r'C:\\Users\\Verghese\\Desktop\\Image_Upload\\ImgResizing'
for file in os.listdir(f):
f_img = f+"/"+file
img = Image.open(f_img)
#img = img.resize((2296,500))
hpercent = (baseheight / float(img.size[1]))
wsize = int((float(img.size[0]) * float(hpercent)))
img = img.resize((wsize, baseheight), Image.ANTIALIAS)
#img.save('resized_image.jpg')
img.save(f_img)
if MsgBox == '1000':
ExitApplication(1000)
elif MsgBox == '800':
ExitApplication(800)
else:
tk.messagebox.showinfo('Return','Please only type 800 or 1000. Try again!')
This was a basic solution and it worked because the parameters were consistent. For example, the images that I received were always of high resolution. This helped with the usage of tinify. However, if they were of low resolution. The tinify solution to reduce file size may not work as the image may become blurry and further reduce its quality.
The image dimension script was simple. It only allowed changing the height of the image to either 1000px or 800px. Through testing, these two amounts caused the least amount of change to the visual of the image. However, this only worked for 90% of the images. They were some images that just did not work and those had to still be edited manually.
If I was to improve this script, more research would have to be done. I would try to find better resources to adjust the height and width more fluidly. Users should be able to enter their desired height/width and the corresponding width/height would adjust accurately, without having the image look skewed or distorted.