It is currently Thu Mar 28, 2024 11:57 pm


All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: Plugin Potrace
PostPosted: Sun Jun 09, 2019 11:27 am  (#1) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2231
Location: Poland
Plugin-potrace.py based on code plugin-trace ( http://gimpchat.com/viewtopic.php?f=9&t=17485) and Potrace by Peter Selinger.

In menu Gimp: Filters->Edge-Detect->Potrace...

Requires separate potrace program be installed.
IMPORTANT: do not use spaces and special characters in directory and layer names.

POTRACE - transform bitmaps into vector graphics
http://potrace.sourceforge.net/
* * * * * * * * *
DESCRIPTION

Potrace is a tool for tracing a bitmap, which means, transforming a
bitmap into a smooth, scalable image. The input is a bitmap (PBM,
PGM, PPM, or BMP), and the output is one of several vector file
formats. A typical use is to create SVG or PDF files from scanned
data, such as company or university logos, handwritten notes, etc.
The resulting image is not "jaggy" like a bitmap, but smooth. It can
then be rendered at any resolution.

Potrace can currently produce the following output formats: SVG, PDF,
EPS, PostScript, DXF, GeoJSON, PGM (for easy antialiasing of
pixel-based images), Gimppath, and XFig. Additional backends might be
added in the future.

A separate program, mkbitmap, is also provided. This program can act
as a pre-processor for Potrace, applying scaling and various filters
to an image before converting it to a bitmap. This is useful for
potracing greyscale and color images.


I do not know if it will work for Linux - so I invite You to Test...


Attachments:
Potrace Sample Lena.png
Potrace Sample Lena.png [ 676.76 KiB | Viewed 9735 times ]
plugin-potrace v 0.1.zip [2.78 KiB]
Downloaded 288 times

_________________
Image

Slava
Ukraini!
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: Plugin Potrace
PostPosted: Sun Jun 09, 2019 12:34 pm  (#2) 
Offline
GimpChat Member
User avatar

Joined: May 10, 2013
Posts: 1389
Location: FInland
Linux Xubuntu 18.04 64-bit, Gimp 2.8. Installed potrace via terminal "sudo apt-get install potrace".

I had this same error with the autotrace plug-in first, but solved it with changing the settings in GUI.
With potrace I'm running always into this:

An error occurred running python_fu_potrace

UnboundLocalError: local variable 'svgimage' referenced before assignment

Traceback (most recent call last):
File "/.gimp-2.8/plug-ins/gimpfu.py", line 699, in response
dialog.res = run_script(params)
File "/.gimp-2.8/plug-ins/gimpfu.py", line 361, in run_script
return apply(function, params)
File "/.gimp-2.8/plug-ins/plugin-potrace.py", line 130, in python_fu_potrace
vectors = pdb.gimp_image_get_vectors(svgimage)
UnboundLocalError: local variable 'svgimage' referenced before assignment


Top
 Post subject: Re: Plugin Potrace
PostPosted: Sun Jun 09, 2019 1:29 pm  (#3) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2231
Location: Poland
Hi Nidhogg.

Thank You very much for the test.

Will probably need to use gtk to solve the problem of spaces in the names of files and directories. :oops:
I am sorry but I will ask - your active layer in the name did not have spaces and non-English characters?
Learning gtk is the next stage of learning - so I will not be able to quickly rewrite the plugin (ala, I plan it - maybe in the meantime an experienced programmer will do it... )

_________________
Image

Slava
Ukraini!


Top
 Post subject: Re: Plugin Potrace
PostPosted: Sun Jun 09, 2019 1:53 pm  (#4) 
Offline
GimpChat Member
User avatar

Joined: May 10, 2013
Posts: 1389
Location: FInland
MareroQ wrote:
Hi Nidhogg.

Thank You very much for the test.

Will probably need to use gtk to solve the problem of spaces in the names of files and directories. :oops:
I am sorry but I will ask - your active layer in the name did not have spaces and non-English characters?
Learning gtk is the next stage of learning - so I will not be able to quickly rewrite the plugin (ala, I plan it - maybe in the meantime an experienced programmer will do it... )

No problem. I renamed the active layer to a single English word before trying the plug-in.
Please don't put all your free time in development of Gimp plug-ins, though they are great. :bigthup
Will keep eye on the topic. Maybe test on another system, but it's almost identical than this except Gimp is 2.10


Top
 Post subject: Re: Plugin Potrace
PostPosted: Sat Jun 15, 2019 1:19 am  (#5) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2231
Location: Poland
@Nidhogg

Potrace also requires"mkbitmap" binaries - the file exists?
With readme:
If you are installing from sources, just do "make install" as root.
If you are installing from a binary distribution, just copy the
"potrace" and "mkbitmap" binaries to a place where the operating
system expects them, such as /usr/local/bin. Also copy the files
"potrace.1" and "mkbitmap.1" to a directory where the operating
system looks for man pages, such as /usr/local/man/man1



Ver. 0.2

-resignation from the selection of directories ["Potrace executable file" and "Output directory to save temp file"] to eliminate the problem of spaces in the names
(which potrace does not tolerate). Requires (for Windows) copying the potrace.exe, mkbitmap.exe, file to the bin Gimp directory.
A location was set for Linux: "/usr/bin/potrace" (maybe Linux requires "/usr/local/bin/potrace" ?). You can edit in line 103.
-add options: "Path visible?": Yes/No
-the rendered image(layer and path) is named as the source layer (accepts spaces - because the name is given after the potrace has finished)


Attachments:
p2.png
p2.png [ 573.7 KiB | Viewed 9587 times ]
plugin-potrace v 0.2.zip [3.11 KiB]
Downloaded 199 times

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: Plugin Potrace
PostPosted: Sat Jun 15, 2019 4:39 am  (#6) 
Offline
GimpChat Member
User avatar

Joined: May 10, 2013
Posts: 1389
Location: FInland
Thanks MareroQ. I got potrace installed with mkbitmap and the mans.
Tested tracing via terminal, works like expected but Gimp still refuses to cooperate.
It's the same error code

Traceback (most recent call last):
File "/home/nidhogg/.gimp-2.8/plug-ins/gimpfu.py", line 699, in response
dialog.res = run_script(params)
File "/home/nidhogg/.gimp-2.8/plug-ins/gimpfu.py", line 361, in run_script
return apply(function, params)
File "/home/nidhogg/.gimp-2.8/plug-ins/plugin-potrace.py", line 140, in python_fu_potrace
vectors = pdb.gimp_image_get_vectors(svgimage)
UnboundLocalError: local variable 'svgimage' referenced before assignment


Top
 Post subject: Re: Plugin Potrace
PostPosted: Sun Jun 16, 2019 4:44 am  (#7) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2231
Location: Poland
@Nidhogg

Sorry - in ver.2 this line (vectors = pdb.gimp_image_get_vectors(svgimage)) should not be anymore, but you can see that I did not save the last change
If you still have patience - try V.3

Ver.3
- removing unnecessary information about vector ("File size"),
- add option "opttolerance"

Potrace FAQ

Question: How can I reduce the number of nodes in the output of Potrace?

Answer: Potrace already makes an attempt to reduce the number of nodes, and this behavior is controlled
by the --opttolerance parameter (or can be turned off entirely with --longcurve).
However, I have decided not to sacrifice quality for quantity, and Potrace will not reduce the number of nodes beyond what it considers tolerable.

For many applications, the problem of reducing output file size can be solved by reducing the resolution of the input image.
This sounds too simple to be true, but can give surprisingly good results.
One of the most common "beginner's mistakes" when using Potrace is to start with an image that contains too much detail or noise.
Blurring the input image can also help, particularly with grey-scale images.


Attachments:
plugin-potrace v 0.3.zip [3.2 KiB]
Downloaded 215 times

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: Plugin Potrace
PostPosted: Mon Jun 17, 2019 3:34 am  (#8) 
Offline
GimpChat Member
User avatar

Joined: May 10, 2013
Posts: 1389
Location: FInland
Yes I have patience. Still same problem on 2.8 Ubuntu 18.04
I'm going to try later on another system with clean install.
Please don't waste your precious coding time with it if you don't want, I can always use Inkscape to get good b/w vector.


Top
 Post subject: Re: Plugin Potrace
PostPosted: Sat Jun 22, 2019 12:41 pm  (#9) 
Offline
GimpChat Member

Joined: Jun 22, 2019
Posts: 8
Hello All!

Gimp 2.10.12 - Linux Mint 19.1 Tessa

@MareroQ

Many thanks, MareroQ, for your really useful plugin!

Unfortunately, due to a different spelling for the parameter --color, the execution did not work on Linux.

The transfer of the color code must be in quotes! For some reason this is not documented and I had to try it for a while in the bash to find out.

To change the file plugin-potrace.py as shown below did the trick!

ImageImage[/img]

As I said, the plugin is very useful and it produces very good results!
That's why I think it would be great if the resulting SVG could be stored in a directory other than the tmp directory for further use.

Maybe that is possible?

Anyway, thanks a lot MareroQ!


Top
 Post subject: Re: Plugin Potrace
PostPosted: Sun Jun 23, 2019 4:11 am  (#10) 
Offline
GimpChat Member
User avatar

Joined: Jan 13, 2011
Posts: 2231
Location: Poland
Hi C-T-S

Welcome to the GimpChat forum.

I'm glad you found a code solution for Linux. Since your patch does not work for Windows, I've added a selection of options for the system.
I never thought that this piece of code would be a problem (although I thought about changing the color code from RGBA to HTML, which Potrace needs - unfortunately without success, although there probably is some working code for RGB change (r, g, b, a) on #HEX).
Regarding svg file saving in another directory:
- it was in ver.1 but with the problem of spaces and national characters,
- in Windows, you can not even delete the temporary svg file (until the plugin has finished running), but you can copy a copy in any directory (no problem with characters and spaces) - but I do not know if you thought of this solution as useful?

ps. Really useful plugin?
The plugin-potrace is just a small adaptation plugin-trace of the best Gimp plug-in by Lloyd Konneker (bootch).
Great - three people have already been interested ...


Attachments:
P v.4.png
P v.4.png [ 388.73 KiB | Viewed 9306 times ]
plugin-potrace v 0.4.zip [3.44 KiB]
Downloaded 252 times

_________________
Image

Slava
Ukraini!
Top
 Post subject: Re: Plugin Potrace
PostPosted: Sun Jun 23, 2019 5:21 am  (#11) 
Offline
GimpChat Member
User avatar

Joined: May 10, 2013
Posts: 1389
Location: FInland
Wohoo, it works!! Thank you MareroQ and c-t-s. Yes the results of Potrace are very good.

MareroQ wrote:
ps. Really useful plugin?
The plugin-potrace is just a small adaptation plugin-trace of the best Gimp plug-in by Lloyd Konneker (bootch).
Great - three people have already been interested ...


It is useful if one is into vectors. I guess this won't draw so much attention, Gimp is pixel editor primarily nevertheless.
Thanks again for your work with this, have a nice day! :jumpclap

Image


Top
 Post subject: Re: Plugin Potrace
PostPosted: Sun Jun 23, 2019 6:38 pm  (#12) 
Offline
GimpChat Member

Joined: Jun 22, 2019
Posts: 8
Hi MareroQ

That's exactly what I meant!
Many Thanks!

I have just discovered your thread 'Plugin-Trace Reactivation'. I also tried Plugin-Trace and experienced that autotrace (binary) installs under Linux in '/ usr / local / bin'. Had to modify the script.

For pure line drawings, however, I like the results of potrace better.

Regarding usability: Of course Gimp is a pixel-based image editor. Nevertheless, from time to time there is the need to trace a bitmap(pencil-drawing). Now, completing this task is possible right from inside of Gimp. No need to start another application, no need to import or open these results into Gimp! Gimp already offers natively the possibility to work with vector paths. IMHO tracing bitmaps extends this sector in the program greatly!

Happy Tracing!http://gimpchat.com/posting.php?mode=reply&f=9&t=17493#


Top
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


   Similar Topics   Replies 
No new posts Attachment(s) Potrace with LIVE PREVIEW

0

No new posts Attachment(s) error when running potrace

2

No new posts Attachment(s) Baby's first GEGL plugin - a very basic GEGL plugin anyone can make.

9

No new posts Can't get plugin to appear (mostly)

3

No new posts Attachment(s) eps plugin crashes

4



* Login  



Powered by phpBB3 © phpBB Group