3

I am attempting to use Simple Inkscape Scripting to programmatically construct an image. I have been working through how to place various objects at (x,y) coordinates on the design surface, but what I want to try and do now is to embed a PNG and at the same time modify its hue.

Currently I have this simplistic test program to bring in my image

fname='MyImage.png' 
image(fname, (0, 0), embed=True, transform='scale(0.02)')

I know from the scripting system itself that the signature of the image command is:

def image(fname, ul, embed=True, transform=None, conn_avoid=False,
          clip_path=None, mask=None, **style):

Using this function, is it possible to programmatically change the hue of a PNG image using either the transform or the style parameters? (I've tried and failed, but that could be anything from my lack of python knowledge to my lack of SVG and CSS knowledge)

The reason I want to do this in a script is that I want to rotate the hue through various steps when embedding several hundred multiple images - and I don't want to do that by hand.

1 Answer 1

1

I'm not familiar with your scripting extension, but there are multiple ways to hue-rotate elements in SVG/Inkscape.

The first is probably the easiest – just add filter: hue-rotate(90deg); to the style. However, this won't actually work inside Inkscape. It seems like it doesn't support this CSS property. It should show up fine when you open the file in most browsers, though.

Then you have SVG-filters, or to be more specific '<feColorMatrix>' with the type set to 'hueRotate'. The documentation for your extension apparently has a section about how to add filters. It is important to note, however, that this does not actually perform true hue-rotation but just an approximation (this might also apply to the first method).

The third method does a true hue-rotate, which is 'Extensions → Raster → HSB Adjust...', but I don't know if there is an easy way to apply this from inside your script.

Lastly, there is also the possibility of batch-processing your image in a raster-editor first and then importing many different files from a directory. GIMP in particular has a batch-processing interface that understands python (--batch-interpreter python-fu-eval), which you can access from the command-line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.