Switch to full style
Post all Gimp scripts and script writing questions here
Post a reply

Working with unicode filenames

Sat Oct 30, 2021 8:25 pm

I like to share with you my experience in handling unicode pathnames. I had trouble with this

import os
image_filename = pdb.gimp_image_get_filename(image)
(fileroot,filename)=os.path.split(image_filename)
fileroot+="\\output"
if not os.path.isdir(fileroot):
os.makedirs(fileroot)

The code would fail if the filename contains unicode. The simple fix is to add a unicode conversion right after the image_get_filename and everything works.

import os
image_filename = pdb.gimp_image_get_filename(image)
image_filename = unicode(image_filename, "utf-8", errors="ignore")
(fileroot,filename)=os.path.split(image_filename)
fileroot+="\\output"
if not os.path.isdir(fileroot):
os.makedirs(fileroot)

I hope this is useful info to others.
Post a reply