Inkscape
This page is concerned with Inkscape, an open source vector graphics editor. Installation/configuration information is for the Mac since that is where I use the program.
A companion page on this wiki is LearningSVG.
References
- Website: http://inkscape.org/
- FAQ: http://wiki.inkscape.org/wiki/index.php/Frequently_asked_questions
- Documentation: http://inkscape.org/doc/. This is an excellent page that refers you not only to a user manual, but also to a few beginner's tutorials that really helped me get starting.
- Inkscape Beginners' Guide.
- Inkscape: Guide to a Vector Drawing Program (online book)
Installation on the Mac
Nowadays the project provides easy to install native builds of Inkscape for macOS. Jump to the download page on the project website and get the DMG file with the app bundle inside.
Configuration
- Language: File > Inkscape Preferences > Interface > Language = en_GB
Extensions
Inkscape is extensible. An extension consists of two files:
- .py file: The extension written in Python
- .inx file: The extension definition file in XML format
Inkscape on Mac requires that you muck around inside the application bundle to add your own extensions. Simply copy the .py and .inx file to this folder, then restart the application:
/Applications/Inkscape.app/Contents/Resources/extensions
Extensions don't work when running the current official app bundle (0.48.2) on Mac OS X 10.7 and above. The fix (as described here) is to insert the following line in /Applications/Inkscape.app/Contents/Resources/bin/inkscape
:
export VERSIONER_PYTHON_VERSION=2.6
I am using the following extensions:
- Remove Guides (download link, forum discussion where I got the download link). With this extension you can quickyl get rid of all the guides in the document (useful if you previously created many guides with "Object > Objects to Guides")
General guidelines for drawing with Inkscape
- Make the document as large as the screen permits, then draw on a large scale. There is no point in doing things on a small scale and popping your eyes out in the process - remember that we are dealing with vector graphics here, so the drawing does not take up more disk space when you make huge drawings, and it will be scaleable to any size later on when you are finished.
- Before you start, outline the drawing you want to make, then create a couple of matching guides. This allows you to use the gazillion of Inkscape's snapping options to align your paths and objects to those guides.
- Watch the status line: It displays all sorts of useful information about the operations you perform. For instance, as a novice I always find it extremely helpful that the status line tells me how I can influence the operation's behaviour by pressing modifier keys (Shift, Ctrl).
Guides
- A guide is a line that is not a drawing artifact itself, but that helps you with aligning objects.
- A guide has an origin point that can be moved along the guide's line.
- A guide will snap when you move its origin point close to the desired snapping target (e.g. a node of a path).
- Creating a guide: Place the mouse pointer into one of the rulers at the document side, then drag into the document. You seemingly drag the guide into existence from out of nowhere.
- TODO: How can guides be placed at an exact x- or y-coordinate (except by closely watching the coordinate indicator)?
Snapping
General things:
- There is an entire toolbar reserved for controlling snapping behaviour. The toolbar usually resides at the right edge of the document window. It can be shown/hidden in the menu under "View > Show/Hide > Snap Controls Bar"
- Further options that control snapping are available under
- File > Document Properties > Snap
- Edit > Preferences > Behavior > Snapping
- Closely watch the document area when you expect snapping to occur. When/if snapping occurs Inkscape displays a relatively short-lived popup tooltip that lets you know just what kind of snapping Inkscape performed for you.
- Snapping can be turned on or off entirely in the Snap Control bar, or by pressing the appropriate keyboard shortcut ("%" is the default)
Snapping recipes:
- As a general rule, paths cannot be snapped to nodes, i.e. you can't move an entire path with the Select tool and hope to snap it to a specific node in another path. A workaround can be to create a guide, let its origin point snap to the desired node, then move the path and let it snap to the guide's origin point.
- Snap the center of a circle: In the Snap Control bar, enable the option "Snap centers of objects". The option "Snap an item's rotation center" possibly works also.
How to draw
The toolbox
One of the most important things in Inkscape is the toolbox - a toolbar with buttons with which you select what you want to do next. Depending on which tool you select Inkscape lets you interact with the canvas in different ways.
There are too many tools to enumerate here, for me the most important ones are:
- The "Select object" tool. This lets you select objects and apply effects to them (e.g. transform, group, etc.).
- The "Node" tool. This lets you select individual nodes in a path and apply changes to the node / path.
- Several tools to draw specific shapes (rectangles, ellipses, etc.). These tools create shape objects.
- Several tools to draw lines and curves. These tools create path objects.
- The "Text" tool. This lets you create and edit text objects. This tool creates text objects.
- The "Fill" tool. This lets you fill bounded areas.
- The "Erase" tool. This lets you delete objects or paths.
- The "Zoom" tool. This lets you zoom in/out to/from the canvas.
Objects: Paths, shapes, texts
The basic object type in Inkscape (or vector graphics in general) is a path. A path consists of nodes. There are 3 types of paths:
- Open path. This is a path with at least one "dangling" node, i.e. a node that is connected to the path on only one side. An open path has ends.
- Closed path. This is a path that has no "dangling" nodes, i.e. all nodes are connected to each other. A closed path has no ends.
- Compound path. This is made up of 2 or more, open or closed paths.
Inkscape also lets you draw a number of pre-defined shapes:
- Rectangles and squares
- Ellipses, circles and arcs
- Polygons and stars
- 3D boxes
- Spirals
Shapes can be seen as paths with specific attributes that you specify when you draw the shape. When you are finished with drawing a shape, Inkscape retains the information what kind of shape the object is, and the information that is necessary to define the shape (e.g. position, width and height of a rectangle). You can convert a shape to a path - when this happens Inkscape forgets about the shape type and any shape-specific attributes, instead it will refer to the shape using path attributes (e.g. position of the corner nodes of a rectangular path).
A third object type besides paths and shapes is text. Just as with shapes, a text can also be converted to a path.
A number of tools generate objects that are just paths:
- Lines (freehand or straight)
- Bezier curves
- Calligraphy
Rectangle shapes
- Select the Rectangle tool, then draw the rectangle on the canvas.
- A square is just a special form of a rectangle. Press the Ctrl key while drawing a rectangle, and Inkscape will try to draw a square if possible.
- Once a rectangle is drawn it shows a number of handles that can be dragged.
- Two handles are for the position of the two opposing corners which define the rectangle's size.
- Two more handles are for the rounding of the rectangle corners.
- The Select tool shows different handles than the Rectangle tool. The Select tool's handles can only be used to resize the rectangle. To change the corner rounding you need to switch to the Rectangle tool.
Ellipse shapes
- Select the Ellipse tool, then draw the ellipse on the canvas.
- A circle is just a special form of an ellipse. Press the Ctrl key while drawing an ellipse, and Inkscape will try to draw a circle if possible.
- Once an ellipse is drawn it shows a number of handles that can be dragged.
- Two handles are for the two radius which define the ellipse's size.
- Two more handles are for the definition of where the ellipse starts/ends. Changing these results in an arc/segment/chord.
- When you change an ellipse's start/end positions so that the ellipse is no longer whole, a number of buttons in the "Tool controls" toolbar let you define how the shape should look like
- Slice (aka Segment). This results in a closed path. The endpoints are connected to the ellipse centre.
- Arc. This results in an open path.
- Chord. This results in a closed path. The endpoints are connected directly.
Polygon shapes
- Select the Polygon tool, then draw the polygon on the canvas.
- A star is just a special form of a polygon. The "Tool controls" toolbar has two buttons that let you toggle between star and polygon.
- Once a polygon is drawn it shows a single handles that can be dragged to adjust both the size and rotation of the polygon.
- Once a polygon is drawn, additional attributes can be changed via the "Tool controls" toolbar:
- Number of corners
- Rounding of corners
- Random scattering of corners and angles
- Spoke ratio (for Star shapes only)
Straight lines (path)
Simple line
- Select the Pencil (aka Freehand) tool.
- Click on the start point, then click on the end point.
- This results in an open path.
Polygon
- Select the Bezier (aka Pen) tool.
- Click on the start point, then click on subsequent points, finally click again on the start point.
- This results in a closed path.
Series of line segments
- Select the Bezier (aka Pen) tool.
- Click on the start point, then click on subsequent points. Double-click on the final point to finish with drawing, or press the Enter key after you have placed the final point.
- This results in an open path.
Both polygons and line segment series can also be created with the Pencil (aka Freehand) tool, but it requires more clicks.
- Click on the start point, then click on the end point.
- Click again on the previous end point, then click on the new end point. This extends the original line.
- Continue until you finally click again on the start point (for a polygon), or until you double-click to finish with drawing and get an open series of line segments.
Freehand lines (path)
- Select the Pencil (aka Freehand) tool.
- Click on the start point, then drag until you reach the end point.
- This usually results in an open path, but if you draw back to the start point then the resulting path will be closed.
- Inkscape can help you with smoothing the jittery line that is likely to result from drawing freehand with a mouse. In the "Tool controls" toolbar adjust the "Smoothing" value. The higher the value the more smoothing Inkscape is going to apply. A tutorial I read somewhere recommended a value between 30-50.
Bezier curves (path)
- Select the Bezier (aka Pen) tool.
- Click-and-drag on the start point
- The start point is the first node of the path.
- The line shown during dragging is the tangent to the curve at the start node.
- The location where you release the mouse button defines the node handle.
- In sum, the location where you release the mouse button defines the amount and direction of curvature that will be applied to the next segment.
- Click-and-drag on the next point
- The point where you click is the next node of the path.
- Again, dragging shows a tangent and the mouse button release location defines the node handle.
- Click on the next point
- Without dragging there is no node handle, which means that the next segment will be a straight line.
- Continue to either click-and-drag (for a curved segment) or simple click (for a line segment) until finished.
- As usual the path is closed when the final click is done on the start point, or it is open if the final click is a double-click done not on the start point.
Brush strokes (path)
- Select the Calligraphy tool.
- The "Tool controls" toolbar has a large number of settings that define what is going to be drawn. The details are beyond the scope of this wiki page, especially because drawing with this tool is usually done on a tablet.
- An essential difference between the Pencil (Freehand) / Bezier (aka Pen) tools and the Calligraphy tool
- Pencil (Freehand) / Bezier (aka Pen) draw an open or closed path, by default with a stroke but no fill.
- Calligraphy draws a closed path, by default with no stroke but a fill.
- This results in a closed path.
Path anatomy
A path consists of
- Nodes
- Segments between nodes
A path can be
- Open. The path has two ends, i.e. two nodes that only have one segment.
- Closed. The path has no ends, i.e. all nodes are connected.
- Compound. The path consists of two or more separate paths, each of which can be open or closed.
There are 4 types of nodes:
- Corner (aka Cusp) node. The Node tool shows these with a diamond-shaped handle.
- Smooth node. The Node tool shows these with a square-shaped handle.
- Symmetric node. The Node tool shows these with a square-shaped handle, i.e. the same shape used for Smooth nodes.
- Auto-smooth node. The Node tool shows these with a circle-shaped handle.
There are 2 types of segments:
- Linear segment with no curvature.
- Bezier segment with curvature.
Node handles:
- A node connects two segments.
- A segment connects two nodes.
- A node can have up to two node handles, one for each of the two segments that it connects.
- A node handle defines the amount and shape of curvature applied to the segment to which it belongs.
- Specifically, the line that is drawn between the node and the node handle is tangent to the curve at the node.
- A node handle can be retracted to remove curvature. If both nodes of a segment have retracted their handle for that segment, the segment is a straight line.
- A retracted node handle can be extracted again.
Node types revisited:
- Corner (aka Cusp) node.
- A node of this type allows an abrupt change in direction between the two segments that it connects.
- The node handles of a corner node can be moved completely independently of each other.
- Smooth node.
- A node of this type enforces a smooth curvature between the two segments that it connects. However, the two curves on either side of the node can be asymmetric.
- The node handles of a smooth node therefore are connected and are aligned with the node itself so that they are all on a straight line.
- If one or both of the node handles of a smooth node are retracted, it seems to be possible to still have an abrupt change in direction.
- Symmetric node.
- Basically the same as smooth node, however the two curves on either side of the node are enforced to be symmetric.
- To achieve this a symmetric node enforces that the two node handles are not only aligned on the same line, but also have the same distance from the node.
- Auto-smooth node.
- Basically the same as smooth node, however an auto-smooth node automatically adjusts its own node handles when certain things change.
- When the auto-smooth node's own position changes
- When the position of a neighbouring node changes
- When the position of a neighbouring node's node handle changes
- Basically the same as smooth node, however an auto-smooth node automatically adjusts its own node handles when certain things change.
- The user is not supposed to manually adjust the segments connected by an auto-smooth node - after all the point is that the auto-smooth node performs this task. An auto-smooth node therefore reverts to a smooth node when the user either manipulates one of the node's handles or one of the segments the node connects.
Node tool
The Node tool lets you adjust all details of a path. The Node tool does not let you change the attributes of a shape or a text.
General notes:
- A path needs to be selected before it can be edited.
- When you select a path the Node tool displays handles for the path nodes.
- When you hover the mouse pointer over a node or segment, the status line displays the node or segment type, and provides a hint how you can manipulate it.
Change the node position:
- Select the node.
- Drag the node to a new location.
Change the curvature of a segment:
- Select one of the nodes of the segment.
- Adjust one or both of the node's handles.
- To retract a node handle, press Ctrl then click the node handle.
- Dragging the handle over the node also seems to work, but it's more tricky.
- To extract a retracted node handle, press Shift while starting to drag from the node.
- Check out the status line for other hints how to simplify some adjustments by pressing the Shift, Ctrl and/or Alt keys.
TODO More details
Filters
Inkscape filters vs. SVG filters
The "Filters" menu has an overwhelmingly large selection of filters that can be applied to objects to create advanced effects. For instance, a very typical filter is the "Drop Shadow" filter available in the "Shadows and Glows" submenu. Each filter has its own specialized dialog for entering the filter parameters. Alas, once a filter is applied you can no longer edit the filter parameters with the same dialog that you used to create the filter. Instead you need to open the "Filter Editor" (also found in the "Filters" menu).
To understand the reason for this you first need to understand how SVG filters work. Check out the LearningSVG page for details, but as a summary we can say that
- An SVG filter is a collection of SVG filter primitives, which are the actual effects.
- An SVG filter has an ID.
- An SVG object, or group of objects, can refer to a single SVG filter by its ID.
With this (basic) understanding of how SVG filters work, let's now come back to Inkscape filters. An Inkscape filter, i.e. an item in the "Filters" menu, is actually composed of a set of underlying SVG filter primitives. When you apply an Inkscape filter, Inkscape transforms the filter parameters into the underlying SVG filter primitives. This is a one-way process that cannot be reversed, so once an Inkscape filter is applied Inkscape has no way to determine from the SVG filter primitives which Inkscape filter was used initially. I like to think of Inkscape filters as "recipes": The recipe (Inkscape filter) has a descriptive name (e.g. "Drop Shadow") and instructions how to process the ingredients (SVG filter primitives) to achieve the desired end product (visual effect).
What happens exactly when you apply an Inkscape filter?
- When you apply the first Inkscape filter to an object, or group of objects, Inkscape creates a new SVG filter, adds some SVG filter primitivies to the SVG filter according to the Inkscape filter parameters entered by the user, and adds a reference to the SVG filter to the object, or group of objects, thus applying the filter.
- But as mentioned above an SVG object, or group of objects, can reference only one SVG filter. So what happens when you apply a second Inkscape filter to an object, or group of objects? Inkscape adds the underlying SVG filter primitives of the second Inkscape filter to the already existing SVG filter that is referenced by the object, or group of objects. The result is that the SVG filter now contains primitives that are a mixture of two Inkscape filters.
A final note on terminology used subsequently on this page:
- Inkscape filter
- A filter to be selected from the "Filters" menu.
- SVG filter
- Visible in the Filter Editor. The Filter Editor calls this just "filter", but I prefer the term "SVG filter" to make the distinction between "Inkscape filter" and "SVG filter".
- SVG filter primitive
- Visible in the Filter Editor. The Filter Editor calls this "effect.
Filter Editor
The Filter Editor allows the user to create, delete and edit SVG filters as well as create, delete and edit individual SVG filter primitives that make up an SVG filter. This section merely provides an overview of the dialog options of the Filter Editor, without going into the details of how to actually achieve visual effects. As the Inkscape user manual puts it:
One needs to have a deep knowledge in SVG filters and matrix mathematics to be able to understand how to use the parameters of every available filter to achieve a specific result.
Managing SVG filters:
- A drop-down menu at the top-left of the editor shows which SVG filters exist in the current document.
- SVG filters are identified by a name (represented as
inkscape:label
attribute of the SVG<filter>
element).- The initial name is taken from the Inkscape filter that created the SVG filter. This can be useful to give a hint to the user later on what kind of Inkscape filter was originally used to create the SVG filter.
- When you apply an Inkscape filter to an object that already has an SVG filter, that filter is renamed after the newly applied Inkscape filter.
- To change the name of an SVG filter, click on the SVG filter item while the drop-down menu is open.
- With the drop-down menu open you also have buttons to create a new SVG filter, or duplicate or delete the selected SVG filter.
- In the drop-down menu you also see how many objects use an SVG filter. This can be useful to find and delete unused filters.
When you select an SVG filter you can edit the SVG filter primitives that it consists of:
- On the right-hand side of the editor you see the list of SVG filter primitives in the SVG filter (called "effect" by the Filter Editor).
- On the left-hand side of the editor you can edit the parameters of the SVG filter primitive that is selected on the right.
Adding/removing SVG filter primitives:
- You can delete the selected SVG filter primitive by clicking the delete button on the left, or by right-clicking the SVG filter primitive on the right.
- You can duplicate the selected SVG filter primitive by clicking the duplicate button on the left, or by right-clicking the SVG filter primitive on the right.
- You can add an entirely new SVG filter primitive by opening the drop-down menu labeled "Add effect" on the right and selecting an entry from the menu.
Ordering
- SVG filter primitives are applied in the order in which they are listed on the right.
- You can change the order via drag & drop.
- SVG filter primitives take their input from the output of a previous SVG filter primitive and/or one of several properties of the object that the SVG filter operates on. I currently don't understand all the details of how this input/output chaining works, except that the SVG standard calls this the "filter primitive tree".
Interacting with objects:
- When you open the Filter Editor and the selected object has an active SVG filter, then the Filter Editor automatically selects that SVG filter and marks the checkbox next to the filter drop-down menu.
- In the SVG filter drop-down menu there is a button (checkmark icon) that lets you select all objects that use the currently selected SVG filter.
- When you select an SVG filter in the drop-down menu the filter is applied to the selected object(s).
Recipes
Get an initial path from an image
- Open an image file
- Select the resulting Image object
- Select "Path > Trace Bitmap"
- If necessary, fiddle around with some of the settings in the dialog that opens
- Click "OK"
- Voilà, a path that describes the image
- Depending on the complexity of the original image, the result is a path with a huge number of nodes. To cut down on nodes, try "Path > Simplify"
Resize
- Select objects to resize
- Select "Object > Transform"
- Select the "Scale" tab
- "Scale proportionally" should probably be selected
- Enter the new size (including the desired unit, typically "px" for pixels
Export a shape to .png
- Select all objects that together make up the shape
- Select the function "File > Export PNG Image"
- Make sure that the export area is set to "Selection". This should set the bitmap size automatically to the size that the objects use in Inkscape.
- Make sure that 90dpi is selected
- Export to the appropriately named .png
Get a Unicode character shape
- Use the Text tool
- Type Ctrl+U
- Enter the Unicode code point for the character that you want to have displayed (e.g. "232b")
- A preview of the character is displayed in the statusbar. Press the Enter key when you are finished.
Note: A font must be installed on the system that has the desired character. If in doubt, double-check with the Unicode Checker app or some other native utility.
Scale a shape
- Open the Transformation dialog (Ctrl+Shift+M, or in the "Object" menu)
- Select the "Scale" tab
- If you want to scale to a fixed target size, change the unit to "px" and enter the target size in pixels
- If you want to scale relatively (e.g. double the size), change the unit to "%" and enter a percentage
Translate multiple nodes
- Select the Node Tool (F2)
- Select a path so that the nodes you want to translate become visible
- Select the nodes you want to translate
- Press the arrow keys to shift/move/translate all selected nodes at once in the direction of the arrow key
- To fine-tune the movement you can change the number of pixels that one key press will shift/move/translate: Edit > Preferences > Behavior > Steps > Arrow keys move by
Cut out a shape from another
- Place shape A over shape B
- Select both shapes
- Select "Path > Difference" from the menu
- Shape A is now gone, and what is left of shape B has the form that was cut out by shape A
- If you still need shape A then make a duplicate of it before doing the difference operation
Cut a shape along a horizontal or vertical line
- Choose the Node tool.
- Select the shape to cut.
- Find a node on the height or width you want to cut.
- Note the type of the node (e.g. corner / cusp node).
- Choose the Bezier tool.
- Create a straight horizontal or vertical line.
- Choose the Select tool.
- Enable Snapping + enable "Nodes" + enable the node type you noted previously.
- Create a horizontal or vertical guide.
- Move the shape to cut until the node you want to use for cutting snaps to the guide's origin point. You may need to zoom in for the snap to work.
- Move the line until it snaps to the guide's origin point.
- Select first the line, then the shape.
- Select "Path > Division" from the menu.
Resize document to fit shape
- File > Document Properties
- Select "Page" tab
- Expand "Resize page to content" in the "Custom size" area
- Click "Resize page to drawing or selection"
- Apparently the keyboard shortcut Ctrl + Shift + R also works.
Drop shadow with a white outline
The combination of drop shadow and white outline allows the shape to be placed on almost any kind of background color.
- Filters > Shadows and Glows > Drop Shadow
- Fill and Stroke > Stroke Paint > Flat Color > ffffffff (i.e. white with no transparency)
- Fill and Stroke > Stroke Style > Width = 3px, Join = Round Join
iOS icon design
Apple's HIG recommend the following icon sizes:
- 22x22 points for toolbar icons
- 25x25 points for tab bar icons
At design time we should draw icons large enough so that they can be easily scaled down to the various resolutions (at the time of writing we have x1, x2 and x3). For me a scale factor of 20 works.
- For toolbar icons this results in a document size of at least 440x440
- For tab bar icons this results in a document size of at least 500x500
- If the same icon should be used for both toolbars and tab bars then the document size should be 550x550 so that downscaling works for both target sizes (550 = 22 * 25)
A few words regarding anti-aliasing:
- As long as we need to support single resolution bitmaps where the number of points is equal to the number of pixels, we need to think about anti-aliasing when we design an icon
- This pertains mainly to straight lines, not shapes, because shapes will almost certainly have to be anti-aliased anyway
- For straight lines we should design the icon so that the lines can be made to align on pixel boundaries after the vector graphics is scaled down to 1x resolution. This is especially important for line width.
- In other words: After downscaling to 1x resolution, a line should always be a multiple of 1 pixel wide (or long). If you design at a scale factor of 20, then make sure that the width of lines is a multiple of 20 pixels.
Important note: At the time of writing this, the Inkscape bitmap export is not capable of aligning lines to pixel boundaries. Since lines are usually stroked paths, this means that a line that is 1 pixel wide will touch 0.5 of each neighbouring pixel, which results in anti-aliasing in the exported bitmap. The only reliable way that I know of to fix this anti-aliasing issue is to manually align lines to pixel boundaries. Do this by translating the elements of the icon by +/- 0.5 pixels on both x/y-axis after you scale down the vector graphics to 1x resolution. If the icon design allows it, another solution, obviously, is to make straight lines that have a width of 2 points (or any even number), because scaling those down to 1x resolution will make the lines take up whole pixels. A solution that floats around the Internet, but which I have found to be unreliable, is to modify the .svg by adding the attribute shape-rendering="crispEdges"
to those style nodes that represent straight lines, then importing the modified .svg into the Gimp. The problem with this approach is that shapes and lines will probably end up mis-aligned and the icon will look like crap. Even more so if the rendering attribute is added to all style nodes, because that causes shapes not to be anti-aliased as well - and as you can imagine a non-anti-aliased circle just doesn't look good.