perspective / free-transform code in inkscape from gimp
![](https://secure.gravatar.com/avatar/d5dd356c317c80e74d8f6169c3be3a8a.jpg?s=120&d=mm&r=g)
G'day guys,
Whenever I have needed to transform a vector Illustration along a perspective I've had to go through the horrible process of:
- importing my svg as paths into gimp - exporting and opening in inkscape - re-drawing all colours, stroke preferences and gradients to suit the new angle. with the transformed rasterisation from gimp as a reference..
free-transform is a feature that I and no doubt many more artists are desperate for within inkscape. Without it creates a limit to the range of artwork produceable from within inkscape
While i was visiting PJRM & NJH in melbourne I discussed this process and how it would be sweet if we could grab some of the gimp code to allow inkscape to do a perspective transform.
PJRM made an awesome modification a while ago where after transforming a group in some way, all ungrouped objects are no longer stuck with a transform matrix applied to each object. The location of all things are now converted into each shape's coords. So that now saves bloat and to my understanding also helped solve one massive problem with inkscape files being rendered in rsvg and transform matricies not being taken into account.
Below is a convo I had with neo on #gimp on irc.gimp.org.
when in melb NJH was eventually convinced that the method for perspective-transforming vectors could be borrowed from the gimps transform method. neo warned me that their transform method is completley different to the method described in the svg spec which is probably what inkscape uses.....
------------ Convo ---------------------
AndyFitz: hi is anyone here familiar with the freetransform code in gimp ( and how it relates to the paths code )
neo_: AndyFitz: what do you want to know?
neo_ is now known as neo
AndyFitz: neo, I'm wondering if its easy to extract the coord translation code for use inkscape ( currently anything I do that requires a perspective transform is done with gimp and imported svg paths then exported to paths again. )
mitch: AndyFitz: how do you do rotation and stuff?
neo: AndyFitz: huh?
neo: AndyFitz: inkscape got to have this code
mitch: AndyFitz: it's all the same in gimp, just matrix transforms. i'm pretty sure it's the same in inkscape
neo: AndyFitz: it's a prerequisite for implementing an SVG parser
AndyFitz: mitch, I rotate the object in inkscape.
neo: no, you apply a transform matrix
AndyFitz: yes you can apply a transform matrix within inkscape but it doesnt yet support free transforms .
mitch: huh?
neo: it is an SVG editor
mitch: you can apply a matrix, so you can do any transform
AndyFitz: in inkscape you can rotate skew stretch etc
neo: you can do exactly what's defined here: http://www.w3.org/TR/SVG/coords.html
neo: you can't do all the things the perspective tool can do
AndyFitz: not all of the svg spec is supported by inkscape yet
neo: it does non-affine transformations
neo: well, transforms are the most basic thing
neo: that's what you implement first
neo: but, as I said, you can't describe all possible transformations in SVG
yakk is now known as yakkGone
AndyFitz: yeah I'm only aware that gimp has code to apply the transform correctly.. right now the transform matrix is only partly implemented by inkscape
AndyFitz: theres no on-canvas way of doing this .. infact inkscape won't render svg with the appropriate transform matrix
neo: you don't seem to understand
neo: gimp does a projective transform
neo: that's a non-affine transformation
neo: which is not defined in SVG
neo: have a look at the transform matrices in SVG, the last row is always 0 0 1
neo: the transform matrix in inkscape is fully implemented, to the extent defined by SVG transformations
AndyFitz: sorry, yes you are right. I'm looking for a way to appropriately transform plain vectors not apply a transformation matrix
Tommer [~tomr@...702...] entered the room.
neo: where's the difference ?
neo: to transform a vector, you apply a transform matrix on it
neo: or rather, you apply it on each point
neo: transforming a path in gimp boils down to calling gimp_matrix3_transform_point() on each of the anchor points
neo: whatever transformation you are doing, doesn't matter
neo: even if a flip is implemented that way
neo: s/if//
AndyFitz: so are the svg spec transform matrix features different to those in the gimp transform matrix ?
AndyFitz: damn I gotta go
AndyFitz: thanks for the great info neo & mitch
neo: AndyFitz: yes, and I already explained you how they are different
AndyFitz: neo yes and I'm totally clueless as to what needs to be done with inkscapes code. thanks for letting me know about gimp_matrix3_transform_point()
AndyFitz: will discuss this on inkscape mailing list and see where we should go
AndyFitz: thanks again, seeya
neo: you can't do what you want to do
neo: you wouldn't be able to save the result to SVG
AndyFitz: hopefully we can with a bit of abstraction. we don't have to work straight to svg only make sure the end result is valid svg. while applying the transform it could be doing anything ... well I hope but its good to have a reality check
neo: AndyFitz: I suggest you read a little about affine and non-affine transformations
![](https://secure.gravatar.com/avatar/bb65b6b3a109d97cf9f8d6c014ede042.jpg?s=120&d=mm&r=g)
On Wed, 9 Feb 2005 19:17:49 +1000, Andy Fitzsimon <andyfitz@...400...> wrote:
free-transform is a feature that I and no doubt many more artists are desperate for within inkscape.
This was planned long ago:
http://inkscape.org/cgi-bin/wiki.pl?PerspectiveObject
All I need to implement this is the math which would perspectively-transform a given path. I can write a trivial kind of such transformer myself, but njh claimed he can do a better one (which would not preserve the number of nodes and thus give more realistic results). I haven't heard from him since...
![](https://secure.gravatar.com/avatar/d5dd356c317c80e74d8f6169c3be3a8a.jpg?s=120&d=mm&r=g)
yeah hes been kinda absent from the list and conference room. :( dont know whats up.
I was looking for the math when talking to neo, hopefully its in gimp_matrix3_transform_point() in the gimp source
preserving the number of nodes is a pretty good thing in my opinion . I didnt know that could be done.
On Wed, 9 Feb 2005 08:05:05 -0400, bulia byak <buliabyak@...400...> wrote:
On Wed, 9 Feb 2005 19:17:49 +1000, Andy Fitzsimon <andyfitz@...400...> wrote:
free-transform is a feature that I and no doubt many more artists are desperate for within inkscape.
This was planned long ago:
http://inkscape.org/cgi-bin/wiki.pl?PerspectiveObject
All I need to implement this is the math which would perspectively-transform a given path. I can write a trivial kind of such transformer myself, but njh claimed he can do a better one (which would not preserve the number of nodes and thus give more realistic results). I haven't heard from him since...
![](https://secure.gravatar.com/avatar/15f5e6abf26f57e1838c29a8356ce7f8.jpg?s=120&d=mm&r=g)
Quoting Andy Fitzsimon <andyfitz@...400...>:
preserving the number of nodes is a pretty good thing in my opinion . I didnt know that could be done.
With bezier curves, it's the easiest way to do it, but you will get some slight perspectrive distortions. Generally you will need to add/remove control points to get the best-looking results.
I can ping njh about his algorithm. He's semi-retired from Inkscape stuff, but we still talk regularly.
-mental
![](https://secure.gravatar.com/avatar/eb3fe37da4a199eb4e3b479d8a57f808.jpg?s=120&d=mm&r=g)
On Wed, 2005-02-09 at 17:59, mental@...3... wrote:
I can ping njh about his algorithm. He's semi-retired from Inkscape stuff, but we still talk regularly.
We talked and it sounds like the best thing to do is to implement the naive (Gimp) version; we can implement the necessary perspective correction atop it.
-mental
participants (4)
-
unknown@example.com
-
Andy Fitzsimon
-
bulia byak
-
MenTaLguY