I'm trying to write a script to automate some things for a project I'm working on, and one of the steps is saving a file as a png. I'm using file_png_save2. When running the script, it errors out with a "Permission Denied" message. However, I can save files to the same folder with no issue if I go through File->Export. I'm running Gimp 2.10 on Windows 11. Here is the code for the script so far:
#!/usr/bin/python
from gimpfu import *
baseURL = "C:\\Users\\MyID\\OneDrive\\Pictures\\ScriptTest\\"
def char_img_164(image, drawable, imgid):
pdb.gimp_edit_copy(image.layers[0])
newImg = pdb.gimp_edit_paste_as_new_image()
pdb.gimp_image_scale(newImg, 164, 164)
dispImg = pdb.gimp_display_new(newImg)
layer = pdb.gimp_image_merge_visible_layers(newImg, CLIP_TO_IMAGE)
pdb.file_png_save2(newImg, layer, baseURL + "test1",imgid+".png",0,9,0,0,0,0,0,0,0)
register(
"char_img_164",
"Image test",
"Test script",
"MyID",
"MyID",
"2023",
"<Image>/Image/ScriptTest/IMG164",
"*",
[
(PF_STRING, "imgid", "Enter ID", "hello")
],
[],
char_img_164)
main()
One error message reads: An error occurred running python-fu-char_img_164 RuntimeError: Could not open 'C:\Users\MyID\OneDrive\Pictures\ScriptTest\test1' for writing: Permission denied
There is also a GIMP message which reads: Calling error for procedure 'file-png-save2': Could not open 'C:\Users\arcad\MyID\Pictures\ScripTest\test1' for writing: Permission denied
Some more attempted troubleshooting:
There was nothing related to the Python interpreter in the security log.
I tried having it write to another disk (E://ScriptText/test1), but got the same error.
I checked the file permissions for the ScriptText and test1 folders, and they're both able to be written to.
I tried running the Python interpreter as Administrator, but still got that error.
Another Edit:
After some more experimenting, it looks like I've found a solution. It may not be the best solution, and feel free to tell me if it isn't, but it is at least a solution. I went into the "Properties" tab for the folder where the image was supposed to be saved and added write permissions for the "Guests" object. I guess either Gimp or Python was running as a guest.