I have this python script to rename image.webp to image_width_height.webp, which runs fine on Windows
Code:
python path_to_script.py path_to_image.webp
In the Chain Editor - Run Command, the set up is like this
- Choose Binary: python
- arg: "path_to_script" {inputfile}
- extension: webp
It returns no error but nothing is changed.
I tried pasting the code to the "Run Python Code" section, but it doesn't provide the "selected files" option so it returned error.
What should I do? I want the selected webp images to include width and height values in their filenames.
The code is
Code:
from PIL import Image
import sys, os
f = sys.argv[1]
if not os.path.exists(f):
print(f"File not found: {f}")
sys.exit(1)
im = Image.open(f)
w, h = im.size
im.close()
base, ext = os.path.splitext(f)
new_name = f"{base}_{w}_{h}{ext}"
os.replace(f, new_name)
PS: Merry Christmas and Happy New Year