Invert color (negative)

Post questions on how to use or achieve an effect in Inkscape.
rapisho
Posts: 4
Joined: Thu Jan 14, 2016 12:37 am

Invert color (negative)

Postby rapisho » Thu Jan 14, 2016 12:55 am

Hello guys, I need your help.
I have a bunch of files that I need to be inverted, they're simple symbols with transparent background, the background should stay, everything else should be inverted, for example black to white.
I opened one of these files in Inkscape, and chose Extensions->Color->Negative and got this message:

Code: Select all

Inkscape has received additional data from the script executed.  The script did not return an error, but this may indicate the results will not be as expected.

Traceback (most recent call last):
  File "color_negative.py", line 9, in <module>
    c.affect()
  File "B:\Programme\InkscapePortable\App\Inkscape\share\extensions\inkex.py", line 265, in affect
    self.getposinlayer()
  File "B:\Programme\InkscapePortable\App\Inkscape\share\extensions\inkex.py", line 207, in getposinlayer
    x = self.unittouu( xattr[0] + 'px' )
  File "B:\Programme\InkscapePortable\App\Inkscape\share\extensions\inkex.py", line 351, in unittouu
    return retval * (self.__uuconv[u.string[u.start():u.end()]] / self.__uuconv[self.getDocumentUnit()])
  File "B:\Programme\InkscapePortable\App\Inkscape\share\extensions\inkex.py", line 304, in getDocumentUnit
    p = param.match(svgwidth)
TypeError: expected string or buffer


What am I doing wrong? I have installed Inkscape on a removable device, does it cause my error?

Thanks in advance!

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Invert color (negative)

Postby Moini » Thu Jan 14, 2016 2:32 am

No, it's the file you have that shows a bug in the extension. The width seems to be missing in your file, and while the file is probably still totally valid, the extension requires it (currently - I think this is fixed for the next version).

The easiest solution, which does not require any svg text editing, might be to copy-paste the contents of the current file into a new file created with Inkscape.

Or, if you want to script things or aren't afraid of editing the SVG code itself, you might try to add a width to your svg file manually, or using a script.

Seems that just setting the document's width to 100% is enough to make it work.

Put it below the Inkscape version in the file, as:

Code: Select all

width="100%"


For understanding where exactly to insert, look into a file that has been created with Inkscape.
(only tested this with one file, make a backup before you edit!)
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

rapisho
Posts: 4
Joined: Thu Jan 14, 2016 12:37 am

Re: Invert color (negative)

Postby rapisho » Thu Jan 14, 2016 7:34 pm

Can you tell me which steps I have to do to make an exact copy of the file? With simply copy and paste I'll get this result, I dont know if this matters when the SVG files are used by a program but it looks pretty different to me:
Zwischenablage01.jpg
Zwischenablage01.jpg (101 KiB) Viewed 4833 times


I also tried to insert
width="100%"
but it had no effect.

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Invert color (negative)

Postby brynn » Thu Jan 14, 2016 9:16 pm

It's hard to tell by looking only at the JPG. But it looks like just a zoom. In the screenshot on the left, the canvas is zoomed in to 590%. On the right is actually zoomed out, to 35%.

Pressing the 1 key is a fast way to zoom to 100% (which is 1:1). But there are several ways to zoom, including a Zoom tool :tool_zoom:

If all you did was copy/paste, the image probably hasn't been changed. Well....unless you're using a Mac. If you're on a Mac, you should probably use File menu > Save a Copy, to save an identical file, instead of copy/paste into a new file.

Unless it's something very subtle that I haven't noticed yet.....??

rapisho
Posts: 4
Joined: Thu Jan 14, 2016 12:37 am

Re: Invert color (negative)

Postby rapisho » Thu Jan 14, 2016 10:09 pm

Im confused by the boarder, is it important? Because the one from the original file is way smaler then the the one from the copy-pasted image. Ive done a screenshot again to explain. I dont know much about svg and inkscape, maybe the border doesent influence how the file is used later. If it is like that please tell me, then I got what I wanted :). Thx for your help btw.
Attachments
Clipboard01.jpg
Clipboard01.jpg (140.76 KiB) Viewed 4812 times

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Invert color (negative)

Postby Moini » Thu Jan 14, 2016 11:29 pm

I just found a second, easier way how you can make Inkscape add a width attribute:
just change the document dimensions (and change them back later).
(detailed description in German)

Statt der Rumkopiererei aus meinem ersten Lösungsvorschlag kannst Du auch einfach via
Datei -> Dokumenteneinstellungen (1. Tab)
eine Seitengröße wählen (z.B. A4), und danach, wenn Du willst, die Seite (das ist der komische Rand da ;) ) auf die Größe des Stoppschildes verkleinern, indem Du das Stoppschild auswählst und in den Dokumenteneinstellungen auf 'Seite in Auswahl einpassen" klickst. Jede andere Seitengröße geht natürlich auch.

Ich habe auch grade ein Einsteigertutorial geschrieben (bzw. meinen Einsteiger-Workshop in Worte + Animationen gegossen), das findest Du auf meiner Webseite, falls Du Dich noch ein bisschen bilden willst ;) (siehe Signatur, letzter Link).
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

rapisho
Posts: 4
Joined: Thu Jan 14, 2016 12:37 am

Re: Invert color (negative)

Postby rapisho » Fri Jan 15, 2016 6:39 pm

Ok this seems to work, thanks :). But I have a new question: I have some files that have some kind of layers, there are stored multiple Icons in one file. If I only select them by mouse or CTRL+A and then do the Extension->Color->Negative nothing happens, also no error message. If I first select them and drag them around and then do the Negative it works, but then they are cut off in the program that uses them, they arent aligned anymore. Here is one such file.

€: Some aditional information: Im modifying a firefox theme, so the svg files are used by firefox.

€2: Ok I solveds the problem by opening the XML tree, then moving the symbols with the align buttons, do the negative and then move back with align buttons. Is there a better solution?
Attachments
icons32.svg
(3.28 KiB) Downloaded 196 times

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Invert color (negative)

Postby Moini » Sat Jan 16, 2016 2:42 am

I think this has to do with the fact that they are all clones of objects that are really living in the defs section of the svg file (no layers in the file, they are just stacked above each other).

Inkscape interprets the "use:" things in the XML (sorry, I've got no better expression for this) as clones.
Normally, if you want to change them, you need to change the original.
In the case of this file, the originals are saved in the 'defs' section of the svg file, which is where information lives that is shared by several objects in the image (e.g. gradients that are used several times, filters that are applied to several objects, patterns that you created, etc.)

Inkscape usually doesn't save clone definitions in the defs section (AFAIK). Objects in the defs section are not accessible for on-canvas editing.

Clones themselves, if the original has a color defined, are not changed when you attempt to change their color (as that is the purpose of clones, that they stay the same). EDIT: overlooked that it /has/ no color defined.

EDIT: See suv's explanation below, please, for a correct explanation better than the rest of this post.

(To be honest, I have no clue why Inkscape *does* change the clones' stroke color with the 'Negative' extension (only) after you have moved them. According to what I know, this should not work, with or without moving. One can even change the stroke color directly, without moving anything.

Probably nobody had anticipated this kind of file ;)

I would unlink them them all from their original before editing.
(Edit -> Clone -> Unlink Clone). This makes them independent, editable objects.

But that might also cause problems if the file **must** stay in the current (unusual, but not invalid, AFAIU) format.)
Last edited by Moini on Sat Jan 16, 2016 3:45 am, edited 1 time in total.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

~suv
Posts: 2272
Joined: Sun May 10, 2009 2:07 am

Re: Invert color (negative)

Postby ~suv » Sat Jan 16, 2016 3:32 am

AFAICT it is not related to the fact that only clones are visible on-canvas (the original objects are defined with unset style properties i.e. the <use> cases can be restyled independently).

The limitation is that Inkscape's color-modifying extensions are external scripts, which have to parse the objects and their SVG source passed from inkscape themselves, without access to Inkscape's internal features. The scripts - since written for use from within Inkscape - had mostly been based on and optimized for SVG code as written by Inkscape. Often there is not enough incentive (or time, or motivation) for extension authors to spend huge efforts to implement a full parser, or many conditionals checking for all possible flavors of e.g. styling a SVG object and whatever else would be needed to support all kinds of variations that may be encountered in handcrafted or externally generated SVG files (yes, there can be differences and variations, while all still valid SVG).

The issue here AFAICT is that the clones (<use> objects) do not have a 'style' attribute in the original file (they are styled via internal stylesheet). The coloreffect-based extensions do not implement their own CSS engine to compute the final style of the clones: they "simply" (not really) expect a 'style' attribute as Inkscape adds to each object which is created or edited with Inkscape (they don't support presentation attributes either yet, but that seems a detail not really relevant here).

The described workarounds trigger that Inkscape copies the computed style (based on the internal stylesheet) as inline CSS into the clone's style attribute, and then the color extensions can work (within the scope of how the clones allow to be restyled).

Moini
Posts: 3381
Joined: Mon Oct 05, 2015 10:44 am

Re: Invert color (negative)

Postby Moini » Sat Jan 16, 2016 3:40 am

Oh... yes, despite /knowing/ I overlooked that the color is indeed not defined... Sorry! (and now I remember we just had this topic with the styling very recently...)

Then simply doing Ctrl+A, then arrow up / arrow down to move them all a tiny bit up and back again would work, too, @rapisho. Quicker than using align and distribute.
Something doesn't work? - Keeping an eye on the status bar can save you a lot of time!

Inkscape FAQ - Learning Resources - Website with tutorials (German and English)

User avatar
brynn
Posts: 10309
Joined: Wed Sep 26, 2007 4:34 pm
Location: western USA
Contact:

Re: Invert color (negative)

Postby brynn » Mon Jan 18, 2016 4:51 pm

I'm not sure if your question was answered by the discussion since I last posted. I was away from my computer for a while. (And I don't understand much of the discussion.) So just in case it wasn't answered.

rapisho wrote:Im confused by the boarder, is it important? Because the one from the original file is way smaler then the the one from the copy-pasted image. Ive done a screenshot again to explain. I dont know much about svg and inkscape, maybe the border doesent influence how the file is used later. If it is like that please tell me, then I got what I wanted :). Thx for your help btw.


It looks to me like the original red icon/object is on a page that's the same size as the icon/object, in your first screenshot. Since you copied the object, and pasted it into a different size page, the page border is different -- much bigger. You must have pasted into a default document, which is usually an a4 size page (roughly 8 x 11 letter size).

Depending on what you're planning to do with the new file later, it might matter very much if it's on the same size page.

To make it exactly the same, there are a few different ways to go about it. Probably you should first look closely at the original file. Notice what size the page is, and notice what size the icon is. Do they match? Or is there a margin? It doesn't look like there's a margin in your first screenshot, but it's hard to tell from the screenshot. (With the SVG file, we could say for sure.)

If there's no margin, here's what I would do. After pasting into a new document, open Document Properties > Page tab > Page Size > Custom Size > Resize Page to Content. There, you can click "Resize page to drawing or selection", and it will make the page automatically the same size as the original.

Another way would be to create a new page that's the size you want it to be, and then paste the icon into it. But then you have to take an extra step (or click) or 2, to center the icon on the tiny page, while Resize Page to Content allows you to skip the centering.

However, if there is a margin in the original file, you'll need to approach a little differently.

I'll leave it there for now, until I know whether your question was already answered, or if not, whether there's a margin or not.


Return to “Help with using Inkscape”