Posts: 3
Threads: 1
Joined: Dec 2023
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
- Linux
Gimp version: 2.10
Hello, i am trying to add an .svg label to images using Python-fu, but getting an unhelpful error code when trying to load the .svg
My console text:
➤> pdb.gimp_path_import(image, "label.svg", TRUE, FALSE)
the error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: execution error
I am guessing this is a path problem. New to this stuff, any tips would be appreciated, thanks!
Posts: 7,132
Threads: 155
Joined: Oct 2016
Reputation:
1,003
Operating system(s):
Gimp version: 2.10
Well, I am no expert either, best wait for Ofnuts to come along. In the meantime this works for me in linux - kubuntu 20.04 / Gimp 2.10.36 from PPA
Code:
➤> image = gimp.image_list()[0]
➤> pdb.gimp_vectors_import_from_file(image,"2.svg", False, False)
➤>
Trying to get everything into a single screenshot. Keeping it simple. 2.svg is a plain SVG from inkscape and is in my home folder.
Posts: 6,339
Threads: 272
Joined: Oct 2016
Reputation:
562
Operating system(s):
Gimp version: 2.10
(12-26-2023, 04:38 AM)Someone Wrote: Hello, i am trying to add an .svg label to images using Python-fu, but getting an unhelpful error code when trying to load the .svg
My console text:
➤> pdb.gimp_path_import(image, "label.svg", TRUE, FALSE)
the error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: execution error
I am guessing this is a path problem. New to this stuff, any tips would be appreciated, thanks!
"label.svg" doesn't tell where the file is, since there is no path component. So this is normally interpreted as "in the current working directory", which is, depending on how Gimp was started:
- the user's home directory on Linux (if started from a desktop icon)
- the CWD of the terminal (if started by entering gimp in a Linux terminal),
- (IIRC) the directory of the .EXE (on Windows)
You can retrieve this information using os.getcwd() (you of course have to import os).
In practice, depending on source:
- If the file can be anywhere, set up a parameter with a PF_FILENAME type to have a file selector,
- If the file is somewhere in the Gimp profile you can find the location of the profile in gimp.directory
- If the file is somewhere in specific user directories, you can have the location of such directories using gimp.user_directory(n) (starting with n=0: Desktop, Documents, Downloads, Music, Pictures, Public, Templates, Videos)
And use os.path.join() to create complete paths: os.path.join(gimp.user_directory(4),'SVG','label.svg')
Posts: 3
Threads: 1
Joined: Dec 2023
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
- Linux
Gimp version: 2.10
12-28-2023, 09:42 PM
(This post was last modified: 12-28-2023, 09:47 PM by Someone.)
(12-26-2023, 09:52 AM)rich2005 Wrote: Well, I am no expert either, best wait for Ofnuts to come along. In the meantime this works for me in linux - kubuntu 20.04 / Gimp 2.10.36 from PPA
Code:
➤> image = gimp.image_list()[0]
➤> pdb.gimp_vectors_import_from_file(image,"2.svg", False, False)
➤>
Trying to get everything into a single screenshot. Keeping it simple. 2.svg is a plain SVG from inkscape and is in my home folder.
Thanks for the reply. I am also using a simple inkscape svg.
When i try to import a path (following your example), the error is slightly different
GIMP 2.10.32 Python Console
Python 2.7.18 (default, Oct 27 2021, 07:49:35) [GCC 11.2.0 64 bit (AMD64)]
➤> image = gimp.image_list()[0]
➤> pdb.gimp_vectors_import_from_file(image,"label.svg", False, False)
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: No paths found in 'C:\Users\bhujl\label.svg'
➤>
Really appreciate the feedback tho!
(12-26-2023, 10:11 AM)Ofnuts Wrote: (12-26-2023, 04:38 AM)Someone Wrote: Hello, i am trying to add an .svg label to images using Python-fu, but getting an unhelpful error code when trying to load the .svg
My console text:
➤> pdb.gimp_path_import(image, "label.svg", TRUE, FALSE)
the error:
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: execution error
I am guessing this is a path problem. New to this stuff, any tips would be appreciated, thanks!
"label.svg" doesn't tell where the file is, since there is no path component. So this is normally interpreted as "in the current working directory", which is, depending on how Gimp was started:
- the user's home directory on Linux (if started from a desktop icon)
- the CWD of the terminal (if started by entering gimp in a Linux terminal),
- (IIRC) the directory of the .EXE (on Windows)
You can retrieve this information using os.getcwd() (you of course have to import os).
In practice, depending on source:
- If the file can be anywhere, set up a parameter with a PF_FILENAME type to have a file selector,
- If the file is somewhere in the Gimp profile you can find the location of the profile in gimp.directory
- If the file is somewhere in specific user directories, you can have the location of such directories using gimp.user_directory(n) (starting with n=0: Desktop, Documents, Downloads, Music, Pictures, Public, Templates, Videos)
And use os.path.join() to create complete paths: os.path.join(gimp.user_directory(4),'SVG','label.svg')
Thanks for the reply.
Sorry, i should have mentioned that i figured out the working directory and already made sure the target file was located in that directory. I was more wondering if i had a single quote/double quote/leading slash type issue.
Basically, i am trying to add a label to a batch of images. Is there a workaround? It doesn't have to be an svg, i could transform to whatever format. I just want to load the label in a new layer in front of the current image, then flatten them to weld it all together.
Again, thanks for taking the time to help out newbs!
Posts: 6,339
Threads: 272
Joined: Oct 2016
Reputation:
562
Operating system(s):
Gimp version: 2.10
(12-28-2023, 09:42 PM)Someone Wrote: GIMP 2.10.32 Python Console
Python 2.7.18 (default, Oct 27 2021, 07:49:35) [GCC 11.2.0 64 bit (AMD64)]
➤> image = gimp.image_list()[0]
➤> pdb.gimp_vectors_import_from_file(image,"label.svg", False, False)
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: No paths found in 'C:\Users\bhujl\label.svg'
➤>
This means that label.svg doesn't appear to have meaning full content. I get this message if I use an empty SVG file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="250" height="250">
<defs>
</defs>
</svg>
So what have you got in that file?
Posts: 3
Threads: 1
Joined: Dec 2023
Reputation:
0
Operating system(s):
- Windows Vista or 7, 8, 10 (64-bit)
- Linux
Gimp version: 2.10
(12-29-2023, 12:59 AM)Ofnuts Wrote: (12-28-2023, 09:42 PM)Someone Wrote: GIMP 2.10.32 Python Console
Python 2.7.18 (default, Oct 27 2021, 07:49:35) [GCC 11.2.0 64 bit (AMD64)]
➤> image = gimp.image_list()[0]
➤> pdb.gimp_vectors_import_from_file(image,"label.svg", False, False)
Traceback (most recent call last):
File "<input>", line 1, in <module>
RuntimeError: No paths found in 'C:\Users\bhujl\label.svg'
➤>
This means that label.svg doesn't appear to have meaning full content. I get this message if I use an empty SVG file:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="250" height="250">
<defs>
</defs>
</svg>
So what have you got in that file?
Ok, sweet, that was the clue i needed.
After saving as a simple .svg instead of an Inkscape .svg, culling the xml data, and simplifying the paths a bit i got it to load!
|