It is currently 17 May 2021, 15:33

• Featuring Members' Works (Image Attachments) •
1: member
2: member
3: member
4: member
5: member

GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  🡆 Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Alpha-Layers to SVG Plug-in

Share your Python Fu Scripts/plug-ins for GIMP here
tim
GL Blogger

Alpha-Layers to SVG Plug-in

Post#1 by tim » 09 Apr 2021, 00:44


Requested by Krikor (I think).
This plug-in will loop through all your layers (named a.png, b.png ....ect),
Select Alpha to Selection each layer and converts to path and then export to svg files (named a.svg, b.svg...etc).
alpha-layers-to-svg.py #
Version 1.0
(2.39 KiB) Downloaded 20 times
alpha-layers-to-svg.py #
Version 2.0 Only try to export to svg if there is something selected on layer
(2.62 KiB) Downloaded 25 times
alpha-layers-to-svg.py #
Version 3.0 If catch error on exporting just try exporting it to error_#.svg as filenames.
(3.15 KiB) Downloaded 21 times
alpha-layers-to-svg.py #
Version 4.0 Let error handling handle error cases on WIndows
(3.34 KiB) Downloaded 19 times
Plug-in Menu Location: /Python-Fu/Alpha-Layers-to-SVG...

Instructions:
  1. Open a custom-font file (or an image with multiple layers named ending in .png ie. a.png, b.png...etc).
  2. Run Plug-in. Select an output directory for svg files to output to. Then OK to run.
  3. That's it. Wait for it to export each layer's alpha-to-selection to svg files.
aka Tin

         

Krikor
Forum Member

Post#2 by Krikor » 09 Apr 2021, 01:27


Tim,
After running the plug-in, this was the screen that came up:
Image

selection-to-path.exe Warning
No selection to convert

GIMP Error
Calling error for procedure 'gimp-image-remove-vectors':
Procedure 'gimp-image-remove-vectors' has been called with value '-1' for argument 'vectors' (#2, type GimpVectorsID). This value is out of range.

Here:
Win10 64 - Samj's Portable 2.10.21
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston

tim
GL Blogger

Post#3 by tim » 09 Apr 2021, 01:43


Error happens when layer is blank, there's no selection so it fails converting to path and so there's no path to export.
Please try version 2.0, where there is a check now to run only there is something to be selected on the layer otherwise it just skips it.
aka Tin

         

Krikor
Forum Member

Post#4 by Krikor » 09 Apr 2021, 01:55


Well ... all the layers had a letter, except the space layer. I don't remember if the selected layer was the space layer or not, or even if the layer had visibility enabled.

I downloaded the new version, restarting Gimp.
PS:

This time it looked like everything was going well, but then ...
However, I noticed in the folder that before the plug-in stopped running, 36 .svg files were created

I think that some of the characters would have caused the interruption. The question mark maybe !? (?)
=========================================================================
Traceback (most recent call last):
File "C:\Users\...\Gimp-2.10.21_Portable-32-64bit-Win\lib\gimp\2.0\python/gimpfu.py", line 741, in response
dialog.res = run_script(params)
File "C:\Users\...\Gimp-2.10.21_Portable-32-64bit-Win\lib\gimp\2.0\python/gimpfu.py", line 362, in run_script
return apply(function, params)
File "C:\Users\...\alpha-layers-to-svg.py", line 52, in python_tt_alpha_layers_to_svg
pdb.gimp_vectors_export_to_file(image,os.path.join(dirname,svgname),vectors)
RuntimeError: Error opening file “C:\Users\...\TestPath03\?.svg”: Input/output error

========================================

GIMP Error
Execution error for procedure 'gimp-vectors-export-to-file':
Error opening file “C:\Users\...\TestPath03\?.svg”: Input/output error
AlphaLayerSvg02.jpg
Krikor - alpha-layers-to-svg tests02
AlphaLayerSvg02.jpg # (57.5 KiB) Viewed 633 times (Thumbnail | Recognize | Sq Tile | LNFI)
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston

tim
GL Blogger

Post#5 by tim » 09 Apr 2021, 08:53


Please give version 3.0 a try.
I have added code to try to catch error on exporting to svg. If it fails on filename such as ?.svg (on WIndows), it'll try to export it as a file named error_#.svg (where # will be replaced by error count, so if it fails 2 times, it'll export to error_1.svg and error_2.svg).
This way the plug-in still gets to finish and then you can look at your output directory to see what files are named that start with error_ and determine what you want to rename the file as some characters are invalid characters to name files with.
aka Tin

         

Krikor
Forum Member

Post#6 by Krikor » 09 Apr 2021, 13:22


Salut Tim !

I tested version 3.0

This time the plug-in has not stopped running.
• Created 75 .SVG files in the destination folder (\ TestPath02);
• Displayed an error for 06 characters (?,>, <, |,:, *);
• The total number of characters in this font is 110. (20 characters were not created or displayed as errors)

Screenshot of the screen with the errors:
AlphaLayerSvg03.jpg
krikor - alpha-layers-to-svg tests003
AlphaLayerSvg03.jpg # (71.06 KiB) Viewed 611 times (Thumbnail | Recognize | Sq Tile | LNFI)
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston

tim
GL Blogger

Post#7 by tim » 09 Apr 2021, 13:55


What are the layer's names....it's probably some character that cannot be renamed as .svg ...
Or are all the layers named with .png at the end?
aka Tin

         

tim
GL Blogger

Post#8 by tim » 09 Apr 2021, 14:20


I am on Linux so I don't get illegal characters for filenames other the forward slash /.
On windows there are more characters that aren't allowed as filenames.
Try version 4.0. I have made it so It tries to run if it fails it error it'll output error_#.svg....
aka Tin

         

Krikor
Forum Member

Post#9 by Krikor » 09 Apr 2021, 14:46


tim wrote:
09 Apr 2021, 13:55
What are the layer's names....it's probably some character that cannot be renamed as .svg ...
Or are all the layers named with .png at the end?
Tim,

The font I'm using can be found in the post Custom Font White Base

Its direct link is Sturdy_White_Base_Kerned

Before applying the plug-in I remove the existing paths.
"I feel that in both art and music, it's not the success that matters but the pleasure it gives you. Focus on the pleasure and the learning will come naturally." - Brian Weston

tim
GL Blogger

Post#10 by tim » 09 Apr 2021, 14:56


Yeah I tried the custom font file you mentioned and see no errors because I am on Linux, Linux is happy with all symbols/characters except for forward slash as expected.
Try version 4 on Windows, you should get bunch of errors but it'll still generate error_#.svg files.
aka Tin

         


GIMP/GL:  Tutorials | Tips | Questions | Interests | Script Requests
Recommendations:  Index | Top 10
Resources:  🡆 Python-Fu Plug-ins | Scheme-Fu Scripts | GIMP
Python:  Lessons | Questions | Exercises
The Arts:  GIMPed | GIMPed Photos | Other | Contests | Public Domain Images | Isolated Images | Blender
Inkscape
Social:  Say Hello | Anything Goes | Shares | FCSP

Post Reply New Topic
  • Similar Topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: No registered users and 41 guests