Skip to main content leehalls.net

Prep for Moving Methods

Sorting out everything for the transition to hugo i find that the wordpress plugins had created multiple copies of images in all different sizes whereas I only need the main size plus the 150x150 as a thumbnail and rather than rename by hand every filen from filename-150x150.jpg to filename-thumb.jpg i wrote the following quick and dirty python to do for it for me.

python code snippet start

#!/usr/bin python
import os
import pdb

path='/home/lee/Pictures'
files = os.listdir(path)

for filename in os.listdir("."):
    if filename.endswith("150x150.jpg"):
        newname=filename[:-11]+"thumb.jpg"
        print(newname)
        os.rename(filename, newname)

python code snippet end

Then it was simply a case of moving them into the relevant folders eg

text code snippet start

- /static
  - img
    - colour
    - bandw
    - lifeanddeath
    - pastlife

text code snippet end