GameIndustry.eu /  Blog /
EnglishPython - Pictures & Metadata


Python - Pictures & Metadata

Eingetragen: 25.08.2023

Python
Python Script: A small Python script to resize JPG images and remove metadata at the same time

Whether you want to change only a handful or hundreds of images at a time, with the script it works in a quick run. Size values and path must of course be adjusted as required.



An existing installation of Python is required. Before running the script, make sure that you have installed the required libraries

 pip install Pillow

 from PIL import Image
import os

# Folder path and target size (pixels)
folder_path = "C:/Pictures/"
target_width = 267
target_height = 400

# Loop through all files in folder
for filename in os.listdir(folder_path):
# Check if it is a JPG file
if filename.endswith(".jpg"):
# Full path to file
file_path = os.path.join(folder_path, filename)

# Open the image
with Image.open(file_path) as img:
# Resize
img.thumbnail((target_width, target_height))

# Remove metadata
data = list(img.getdata())
img_without_meta = Image.new(img.mode, img.size)
img_without_meta.putdata(data)

# Save and overwrite image
img_without_meta.save(file_path)

 

 

  Rules for posting comments can be found in the F.A.Q.