It is currently Tue Jul 23, 2024 6:17 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 17 posts ] 
Author Message
 Post subject: Path Save and Load Script for GIMP
PostPosted: Mon Oct 10, 2016 10:54 pm  (#1) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4041
Location: Canada
I looked at Path/Vectors Export and Import and it seems it only does absolute pixels loading when importing.
So I wrote this script to "Save" and "Load" Path with 3 extra loading methods on top of ABSOLUTE(pixels) mode
RELATIVE (percentage) -- this mode will scale based on image width and height
RELATIVE WIDTH KEEP ASPECT RATIO -- this mode will scale based on width keeping aspect ratio of original path when saved.
RELATIVE HEIGHT KEEP ASPECT RATIO -- like RELATIVE WIDTH KEEP ASPECT RATIO but based on HEIGHT
This should help instead of having to manually scale the path after importing.

Imagedownload zipped .py file
Just like click vectors and choose Save... or Load... (You must have at least one path to access these menus, even if it's just an empty path)

more details. --> here

Image

Image

_________________
TinT


Last edited by trandoductin on Wed Nov 28, 2018 12:46 pm, edited 4 times in total.

Share on Facebook Share on Twitter Share on Orkut Share on Digg Share on MySpace Share on Delicious Share on Technorati
Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Tue Oct 11, 2016 10:06 am  (#2) 
Offline
GimpChat Member

Joined: Sep 13, 2016
Posts: 137
Tryed your script ;-)
Works, but only if there is at least ONE path (empty suffices) available.

Reason why is not yet clear to me ...


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Tue Oct 11, 2016 11:27 am  (#3) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4041
Location: Canada
yeah i don't know how to solve that either.
When you load you shouldn't need an empty path (or at least one opened) but i don't know how to make it so that it doesn't need a path, I am guessing that's just how the menu items on <Vectors>/ menu register works but i am not too sure either.

_________________
TinT


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Wed Oct 12, 2016 3:16 am  (#4) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2260
Location: Poland
Thank You for this plug-ins.

Only suggestions:

1. Change of location in the menu Gimp(very simple).
   "<Vectors>/vectors-import/Paths Load...",             #Menu path
   "<Vectors>/vectors-export/Paths Save...",             #Menu path

2. Adding options at load / save: select the filename and directory ?
(probably very difficult - perhaps impossible - creates the first empty paths.txt while loading the Gimp)


Attachments:
My suggestion location in menu.png
My suggestion location in menu.png [ 60.08 KiB | Viewed 3305 times ]
Request new options.png
Request new options.png [ 17.74 KiB | Viewed 3305 times ]

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Wed Oct 12, 2016 11:09 am  (#5) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
IMHO you script should work a bit differently:

1) let people export a standard SVG (no script needed)
2) work as an improved SVG import: load the path with pdb.gimp_vectors_import_from_file(image, filename, merge, scale) (which may have useful options already) and then apply the required transformations on the loaded path.

Benefits:
1) you don't have to deal with the export (or with the complexities of the SGV format)
2) your script also applies to SVG from non-Gimp sources

_________________
Image


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Wed Oct 12, 2016 12:43 pm  (#6) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4041
Location: Canada
I meant it to be a hack with its own format just to be used in GIMP. Didn't think about other apps.
I looked at the .svg exported and trying to import that .svg well would require a lot more brain power than i have right now... :hehe

_________________
TinT


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Wed Oct 12, 2016 4:16 pm  (#7) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4041
Location: Canada
MareroQ wrote:
Thank You for this plug-ins.

Only suggestions:

1. Change of location in the menu Gimp(very simple).
   "<Vectors>/vectors-import/Paths Load...",             #Menu path
   "<Vectors>/vectors-export/Paths Save...",             #Menu path

2. Adding options at load / save: select the filename and directory ?
(probably very difficult - perhaps impossible - creates the first empty paths.txt while loading the Gimp)


I don't know how to allow a filename to be selected and at the same time allow user to choose a path from that file because the list of names in the drop down is generated at run time.
Probably involves like some live update like the ability to preview the result almost i think not too sure but i am not good enough to have user select a filename and at the same populate the drop down list :oops:

_________________
TinT


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Wed Oct 12, 2016 6:16 pm  (#8) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
trandoductin wrote:
I meant it to be a hack with its own format just to be used in GIMP. Didn't think about other apps.
I looked at the .svg exported and trying to import that .svg well would require a lot more brain power than i have right now... :hehe


Not at all, using pdb.gimp_vectors_import_from_file(image, filename, merge, scale) means that Gimp is going to handle all the SVG decoding. You give it a file on one end (from a PF_FILENAME parameter, can't be any easier) and get a gimp.Vectors object at the other end so to speak.

And you already know how to do the transforms.

_________________
Image


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Wed Oct 12, 2016 6:41 pm  (#9) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4041
Location: Canada
What that easy?
Maybe i just need to add a script that calls this
pdb.gimp_vectors_import_from_file(image, filename, merge, scale)
and after user choose .svg filename
and choose a loading method
for choosing a loading method i need to know original image size that path was exported.
looked at the svg.
it's under "viewBox" is there gimp's methods to get that info.
or do I parse that myself?

_________________
TinT


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Thu Oct 13, 2016 1:51 am  (#10) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
Could be done by looking at the SVG file with the xml.eTree library... but why would you need the size of the original image?

_________________
Image


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Thu Oct 13, 2016 12:38 pm  (#11) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4041
Location: Canada
ofnuts wrote:
Could be done by looking at the SVG file with the xml.eTree library... but why would you need the size of the original image?

Because that's how i can have load methods like RELATIVE (percentage), RELATIVE WIDTH KEEPING ASPECT RATIO and RELATIVE HEIGHT KEEPING ASPECT RATIO. I need the original image's dimensions in order to know how the path sits on the original image in order to apply the same percentage on to the current image (that it's being loaded on).

_________________
TinT


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Fri Oct 14, 2016 3:42 pm  (#12) 
Offline
Script Coder
User avatar

Joined: Oct 25, 2010
Posts: 4757
Quite simple actually:
import  xml.etree.ElementTree as ET
import sys

if len(sys.argv) < 2:
    print("Usage: %s {svgfile}" % sys.argv[0])
    exit(2)

svgFile=sys.argv[1]
svg=ET.parse(svgFile).getroot()
print '%7.2f %7.2f %s' % (float(svg.attrib['width']),float(svg.attrib['height']),svgFile)


As far as I can tell, xml.etree.ElementTree is part of the Python package distributed with the Windows Gimp version.

In some files, you'll find heigh/width specified as '150px' or '2.4in' or '1200pt' so you may have to be a bit cautious when converting the values. Some files also define a 'viewBox' attribute.

_________________
Image


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Fri Oct 14, 2016 3:48 pm  (#13) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4041
Location: Canada
I did it using the viewBox attribute because i only want to deal with exported path by GIMP. :hehe

_________________
TinT


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Sat Oct 15, 2016 3:13 am  (#14) 
Offline
Script Coder
User avatar

Joined: Feb 18, 2011
Posts: 4827
Location: Bendigo Vic. Australia
Trandoductin instead of using the image size could you make use of the bounding box of the current selection if one exists.

_________________
Image
No matter how much you push the envelope, it'll still be stationery.


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Sat Oct 15, 2016 6:22 am  (#15) 
Offline
Global Moderator
User avatar

Joined: Oct 06, 2010
Posts: 4050
Graechan wrote:
Trandoductin instead of using the image size could you make use of the bounding box of the current selection if one exists.


I like the way you think...

_________________
"In order to attain the impossible, one must attempt the absurd."
~ Miguel de Cervantes


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Sat Oct 15, 2016 2:26 pm  (#16) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4041
Location: Canada
Shhh Graechan.. :hehe
I'll update it soon

_________________
TinT


Top
 Post subject: Re: Path Save and Load Script for GIMP
PostPosted: Sat Oct 15, 2016 4:34 pm  (#17) 
Offline
Script Coder
User avatar

Joined: May 07, 2014
Posts: 4041
Location: Canada
Okay just updated the download link to point to version 3 of script.
Which works on selection bounding box.
It's easy because this script i am calculating the path myself.

But I tried to also apply this to the Import SVG Path with load methods and it's tripping me out i kept getting weird bugs.... i don't know about that one..maybe save it for another day when i am not so tripped out by simple scaling math.

_________________
TinT


Top
Post new topic Reply to topic  [ 17 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts script to load text file and create text layer

6

No new posts Attachment(s) Shortening mouse/keystrokes save/export script or method to implement?

41

No new posts Where did GIMP save my file, & how do I change default save location

5

No new posts Attachment(s) i struggle with the option to copy the path - the path where a file i

3

No new posts Cant load GMIC plugin in gimp

2



* Login  



Powered by phpBB3 © phpBB Group