jankovicsandras / imagetracerjs

Simple raster image tracer and vectorizer written in JavaScript.
The Unlicense
1.31k stars 171 forks source link

imagetracer.js for InkScape #47

Closed vmario89 closed 4 years ago

vmario89 commented 4 years ago

Hi,

i did some work with InkScape and had the idea to make a wrapper for InkScape > https://inkscape.org/~MarioVoigt/%E2%98%85imagetracerjs-for-inkscape-1x

If you like just add it to your readme / docs =)

grafik

grafik

regards, Mario

jankovicsandras commented 4 years ago

Hi Mario,

Thanks for your great work! I've updated the README with this.

bosd commented 3 years ago

Hi @vmario89 Thanks for creating this great plugin. However I ran into a few issues on Fedora Linux.

The dry run of the nodecli command failed. node nodecli ../panda.png -outfilename outpanda.svg

This can be solved by using the latest nodejs and imagetracer.

Second, there is an issue in the python script within the path and file structure in general. Don't have an complete solution for this issue yet. Basically os.path is not working properly in linux distro. (maybe permission related)

This causes that the nodecli.js is'nt correctly called. For testing purposes modded to code to point to nodecli. But that is not an good solution as os.path is also called on the export file. (At least the nodecli script is called, as it wasn't doing that earlier)

The nodecli.js didn't get called because of the whitespaces in the string. Fixed it by changing (fablabchemnitz_imagetracerjs.py): with os.popen(command, "r") as tracerprocess: to with os.popen('command', "r") as tracerprocess:

Fixed the function call of imagetracer by changing line:

if __name__ == '__main__':
    Imagetracerjs().run()

to

if __name__ == '__main__':
    Imagetracer().run()

Now the functions are called. One stop closer to get it working. But there still is no (temp) output file generated.

vmario89 commented 3 years ago

Hi, thanks for reply. I had a look into it but i cannot see the issues right now. I tested on my Ubuntu system and it works flawlessly. did you try the latest code? https://gitea.fablabchemnitz.de/MarioVoigt/mightyscape-1.X/src/branch/master/extensions/fablabchemnitz/imagertracer.js

the docs can be found at https://stadtfabrikanten.org/display/IFM/Imagetracer.js

my test with raster image: grafik

converted with imagetracer: grafik

at least the changing from "Imagetracerjs().run()" to "Imagetracer().run()" looks strange. That should not work because there is no class with that name. you should convert back.

making os.popen(command, "r") to os.popen('command', "r") will destroy command variable content. Instead it will be a static string with content "command".

my inkscape extension already uses the latest imagetracer.js from this repo which is september 2020. using that commit https://github.com/jankovicsandras/imagetracerjs/commit/fd7252f20e5a832adc326fbe4e88b17530d4747e

regarding node version: i am not sure about node version. i installed some node version with the apt package manager. should be some regular rpm package on Fedora. "node -v" gives me "v10.19.0" . So it seems i am using a really old one. but it works fine with it. should do the same job with node v11/12/13/14 hopefully.

please try the following dry code line which would be called from that extension (you might need to change the working directory to your path accordingly):

node imagetracerjs-master/nodecli/nodecli.js /tmp/imagetracerjs.png ltres 1.0 qtres 1.0 pathomit 8 rightangleenhance true colorsampling 0 numberofcolors 16 mincolorratio 0 numberofcolors 16 colorquantcycles 3 layering 0 strokewidth 1.0 linefilter false scale 1.0 roundcoords 1 viewbox false desc false blurradius 1 blurdelta 20.0

some more questions to check:

regards and thanks sharing your feedback with me, Mario

bosd commented 3 years ago

Thaks Mario! for the info! I downloaded a fresh version from your gitea (Do you mind sharing that on the inkscape plugin page of imagetracer as well, as it is very hard to find this repo)

please try the following dry code line ....

node imagetracerjs-master/nodecli/nodecli.js /tmp/imagetracerjs.png ltres 1.0 qtres 1.0 pathomit 8 rightangleenhance true colorsampling 0 numberofcolors 16 mincolorratio 0 numberofcolors 16 colorquantcycles 3 layering 0 strokewidth 1.0 linefilter false scale 1.0 roundcoords 1 viewbox false desc false blurradius 1 blurdelta 20.0

The dry code works perfectly!

some more questions to check: what python version do you run by the way? "python3 -V" gives me "Python 3.8.5".

Python 3.9.2

> what InkScape version do you use? Instead prior 1.0 used old python 2 which will not work. regards and thanks sharing your feedback with me, Mario

I use inkscape version: 1.0.2 (e86c870879, 2021-01-15)

Node version is:

node -v
v14.16.0

Running the newly downloaded code from within inkscape I still have the following error:

image /bin/sh: node: command not found

vmario89 commented 3 years ago

Hi,

thanks for feedback. I know. InkScape gallery has a small "link" URL which leads to the gitea repo. But most people oversee it (i did it too a long time ago^^). But maintaining on InkScape gallery is a bit frustrating. In newer InkScape version there is an extension manager. Real idea would be to integrate it directly in that manager system.

can you tell me where your node exectuable is located? You can try which node on console. Should return the path were node gets started from. For me it is usr/bin/node

could be that your system's PATH environment variable does not contain the node command. the following might help: echo 'export PATH=$PATH:/usr/bin' >> $HOME/.bashrc

Do you execute InkScape from the same user as you execute InkScape?

vmario89 commented 3 years ago

please leave me some feedback when you have time. maybe i have an idea then :-)

bosd commented 3 years ago

Yes, I run inkscape from the same user.

$ which node
/usr/bin/node

Running command: echo 'export PATH=$PATH:/usr/bin' >> $HOME/.bashrc does not give any result / feedback

vmario89 commented 3 years ago

hmmmm ... what happens if you run inkscape as root? i think it has to be a permission issue or $PATH environment variable issue

bosd commented 3 years ago

Some follow up info. Normally I start Inkscape from the menu or by double clicking an svg file.

The terminal did not recognize the command inkscape But suggested it to install. (Don't know why, maybe my previous install was from flathub?) Either way inkscape installed version

``` bash: inkscape: command not found... Install package 'inkscape' to provide command 'inkscape'? [N/y] y * Waiting in queue... The following packages have to be installed: aspell-12:0.60.8-5.fc33.x86_64 Spell checker gtkspell3-3.0.10-6.fc33.x86_64 On-the-fly spell checking for GtkTextView widgets inkscape-1.0.2-1.fc33.x86_64 Vector-based drawing program using SVG libgdl-1:3.34.0-3.fc33.x86_64 GNOME docking library librevenge-0.0.4-19.fc33.x86_64 A base library for writing document import filters libwpd-0.10.3-6.fc33.x86_64 A library for import of WordPerfect documents libwpg-0.3.3-5.fc33.x86_64 A library for import of WordPerfect Graphics images potrace-1.16-4.fc33.x86_64 Transform bitmaps into vector graphics python3-scour-0.38.1-1.fc33.noarch An SVG scrubber Proceed with changes? [N/y] y ```

From this install the extenstion directory changed to /usr/share/inkscape/extenstions Had to open in in root nautilus to be able to cope the extension files there. using the plugin created an error.

``` (node:2970301) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created) Traceback (most recent call last): File "/usr/share/inkscape/extensions/fablabchemnitz/imagertracer.js/imagetracerjs.py", line 173, in Imagetracerjs().run() File "/usr/share/inkscape/extensions/inkex/base.py", line 140, in run self.save_raw(self.effect()) File "/usr/share/inkscape/extensions/fablabchemnitz/imagertracer.js/imagetracerjs.py", line 154, in effect newGroup.attrib['transform'] = "matrix(" + \ TypeError: can only concatenate str (not "NoneType") to str ```

Next attempt running $sudo inkscape Another error..

``` (node:2979169) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead. (Use `node --trace-deprecation ...` to show where the warning was created) /usr/share/inkscape/extensions/fablabchemnitz/imagertracer.js/imagetracerjs-master/nodecli/nodecli.js:78 function(err){ if(err){ console.log(err); throw err; } console.log( outfilename+' was saved!' ); } ^ [Error: EACCES: permission denied, open '/tmp/imagetracerjs.png.svg'] { errno: -13, code: 'EACCES', syscall: 'open', path: '/tmp/imagetracerjs.png.svg' } Traceback (most recent call last): File "/usr/share/inkscape/extensions/fablabchemnitz/imagertracer.js/imagetracerjs.py", line 173, in Imagetracerjs().run() File "/usr/share/inkscape/extensions/inkex/base.py", line 140, in run self.save_raw(self.effect()) File "/usr/share/inkscape/extensions/fablabchemnitz/imagertracer.js/imagetracerjs.py", line 154, in effect newGroup.attrib['transform'] = "matrix(" + \ TypeError: can only concatenate str (not "NoneType") to str ```

P.S. Also tried to use the plugin on a different machine running windows 10. That one was also unable to complete the operation due to errors. (All of the time I used the latest source from your git).

vmario89 commented 3 years ago

The stack lines

  File "/usr/share/inkscape/extensions/fablabchemnitz/imagertracer.js/imagetracerjs.py", line 154, in effect
    newGroup.attrib['transform'] = "matrix(" + \
TypeError: can only concatenate str (not "NoneType") to str 

makes no sense to me. seems the temp dir is not accesible by the node process so no svg is written. the toolchain cannot continue without svg input. but it should throw another error.

i tested it again using InkScape 1.0.2 on Windows. Just copied imagetracer.js directory into extensions dir and everything is fine. No errors generated.

stupid question: don't you run the extension from visual GUI? Are you testing it by CLI? I never made this extension for CLI mode. At least i never tested it.

bob4081 commented 4 months ago

I'm getting this error. I'm on Windows 10. Inkscape 1.3.2

Error while processing input: [TypeError: undefined is not a function]

Check the image file (maybe convert and save as new file) and try again.

Your parser command: node --trace-deprecation imagetracerjs-master\nodecli\nodecli.js imagetracerjs.png ltres 1.0 qtres 1.0 pathomit 8 rightangleenhance false colorsampling 0 numberofcolors 16 mincolorratio 0 numberofcolors 16 colorquantcycles 3 layering 1 strokewidth 1.0 linefilter false scale 1.0 roundcoords 1 viewbox false desc true blurradius 1 blurdelta 20.0

vmario89 commented 4 months ago

this is hard to debug. do you have any additional infos? how did you install the inkscape extension?

i cannot see from where that typerror comes. please send me a full error stack trace and/or screenshot please