GameIndustry.eu Logo

2019 2017 2019 2019   2018  2023   2015 
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), don't forget to adjust path
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)

 

 

Your opinion is important – please leave a comment!

×

BB-Code Explanations

Here are the BB-Codes you can use:

  • [b] for bold text: [b]Text[/b] turns into Text
  • [i] for italic text: [i]Text[/i] turns into Text
  • [u] for underlined text: [u]Text[/u] turns into Text
  • [spoiler] for hidden Text: [spoiler]Hidden Text[/spoiler] turns into Hidden Text
  • [url] for hyperlinks: [url]http://example.com[/url] becomes a clickable link  
  • [url=link]text[/url] for named hyperlinks: [url=http://example.com]Visit me[/url] turns into Visit me  
  • [github] for GitHub links: [github]http://github.com/example[/github] turns into a  GitHub-Link

0 Comments