View Single Post
Old 12-25-2025, 03:21 AM   #119
nqk
Fanatic
nqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beautynqk does all things with Zen-like beauty
 
Posts: 588
Karma: 32228
Join Date: Feb 2012
Device: Onyx Boox Leaf
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

Last edited by nqk; 12-25-2025 at 05:29 AM.
nqk is offline   Reply With Quote