Inkscape.org
Creating New Extensions Error transforming image (or group)
  1. #1
    DrQt DrQt @DrQt

    here is the function I'm using and the error.

    Any idea what might be wrong?

     

    def transform2(angle,scale,min_x,min_y,move_x,move_y, elm):
    	tr            = inkex.Transform()						
    	tr.add_translate(0 - min_x, 0 - min_y)
    	elm.transform = tr * elm.transform
    	elm.apply_transform()
    
    	tr            = inkex.Transform()
    	tr.add_scale(scale)
    	elm.transform = tr * elm.transform
    
    	tr            = inkex.Transform()
    	tr.add_rotate(angle, 0, 0)
    	elm.transform = tr * elm.transform
    
    	tr            = inkex.Transform()						
    	tr.add_translate(move_x, move_y)
    	elm.transform = tr * elm.transform
    	elm.apply_transform()
    	return elm
    
    
    inkex.utils.debug(elm) prints: image
    
    
    Traceback (most recent call last):
      File "comic_cave.py", line 431, in <module>
        Comic_Cave().run()
      File "/tmp/.mount_inkscaigljym/usr/share/inkscape/extensions/inkex/base.py", line 131, in run
        self.save_raw(self.effect())
      File "comic_cave.py", line 419, in effect
        transform2(angle,scale,min_x,min_y,move_x,move_y,img)
      File "comic_cave.py", line 127, in transform2
        elm.apply_transform()
      File "/tmp/.mount_inkscaigljym/usr/share/inkscape/extensions/inkex/elements/_base.py", line 165, in __getattr__
        raise AttributeError(f"Can't find attribute {self.typename}.{name}")
    AttributeError: Can't find attribute Image.apply_transform

     

  2. #2
    inklinea inklinea @inklinea⛰️

    I'm not 100% sure of the proper way to apply transforms in Inkscape.

    What I found is that all transforms have to take account of the possibility that the layer ( group ) itself has a transform applied to it.

    This happens often when the user has used Edit>Resize Page to Selection. 

    How I got around it is to wrap the group or object in another temporary group, then get the .composed_transform for the inner object, then pop it out and delete the temp group.

    I could then multiply my own transform by the obtained composed transform. 

    This is probably not the way to do it, It's just something I came up with - It does work though.

    This extension uses that technique to translate : https://inkscape.org/~inklinea/%E2%98%85simple-registration

    If anyone is able to post a fool proof way, I would definitely be interested.

  3. #3
    DrQt DrQt @DrQt

    regarding my bug...
    .apply_transform() on Image: no bueno ... who knew.

    removing it prevents the crash.

    I'll check out your approach.  That doesn't sound like an edge case I'll encounter.

    Sneaking suspicion that I shouldn't be relying in .add_rotate.. and get jiggy with matrices instead.

  4. #4
    inklinea inklinea @inklinea⛰️

    Glad you found a solution. 

    I would point out then a lot of published clipart files created in Inkscape, already have layer transforms on them. 

    This is because the last stage of publishing is often to resize the canvas to suit the artwork. 

    It tripped me up in the beginning :)

Inkscape Inkscape.org Inkscape Forum Creating New Extensions Error transforming image (or group)