-
-
Notifications
You must be signed in to change notification settings - Fork 428
More advanced icon editing
Important
Pixel alignment is such a fundamental topic that it's covered in the Basic Concepts guide. Go and read that section if you haven't already, and then come back here. It also covers why we draw icons at different sizes in the first place.
Generally, you don't draw things aligned at fractional pixels. There are some exceptions where it does make sense, however. The half-pixel grid is most useful for this, and it's most useful...
- Where two angled, symmetrical lines come together at a point.
- To look good, the anti-aliasing effects should look the same on both sides of the "V" shape where the lines join, AND
- the inner point inside the joined lines should be in the centre of its own pixel.
- If you join the two lines at a pixel boundary instead, the joining point becomes blurry and indistinct in the rendering
- When you're aligning a horizontal or vertical line that's an odd number of pixels wide so that its top and bottom edges align to pixels.
- The same thing with a circle that has to be an odd number of pixels in diameter.
You still need to keep the outer lines of shapes as a whole nicely aligned at pixel boundaries.
Let's take the example of a new mimetype icon for an MSX home computer ROM image, requested in #2505. I'm drawing the 22 pixels square size, which is one of the smaller sizes.
An immediate problem with this icon is that the accurate MSX logo doesn't really want to align neatly to a one-pixel grid at less than 22 pixels wide. Here's the source image:
I found that it's sort of OK at 64 pixels, but at 22 pixels, I need to fit it into a 14x5 pixel grid! At this size, the horizontal lines of the "S" in particular require fractional sizing if they're to retain the right proportions, and that's a real problem. What can we do about it?
I first made the top and the bottom of the logo align into a space 5 pixels high, and started by redrawing the "S" with half circles and the Bezier curve tool. The half-pixel grid doesn't help very much with the "S" except horizontally, but in the end, I was able to calculate the line widths, and get everything centred. Sometimes this involves hand-editing the coordinates of individual points and multiple selections of points.
Note
When you're editing a Bezier curve, you can either move sets of points or the Bezier object as a whole. If you're moving the object as a whole, then certain snapping options allow you to snap the outer edge of the lines to grid intersections.
Note how verticals and horizontals of the file icon outline butt up against the whole-pixel grid, and how the outer edges of the "MSX" try to match a whole-pixel edge where they can. The "M" and "X" are horizontally symmetrical, and the "X" is vertically symmetrical.
I've tried to "surround" most of a pixel in various key places to lead the eye. The key pixels are the places in the "M" where strokes join, the rounded turns in the "S", and the crossing in the middle of the "X". I also used the half-pixel grid (pink centre dots) to align the inner angles of the "M" (sometimes called "crotches" by type nerds). The "X" is more freely aligned than the "M", but its inner angles at the crossroads are on either the vertical or the horizontal axis of the half-pixel grid. I'm particularly using the half-pixel grid for the "M" and "X" because these letters need to be highly symmetrical around the point where their letter strokes join.
Purists might complain about the inner blur inside the icon on the "S". However, the eye won't see that, and it gets the letter weight (boldness) correct alongside the other sizes. The horizontal lines of the S have a rhythmic layout which makes the shade of dark blue-grey between the parts of the S the same above and below its centreline.
- It's the outer outlines of a shape as a whole that matter most
- Make it hit as many horizontals and verticals as you can, especially at the outer edges
- Inside a complex shape, alignment of inner lines matters a lot less at smaller sizes
- But try to make certain forms symmetrical, and align sharp inner angles with pixel centres
- Symmetrical forms always need pixel-symmetrical renderings and half pixel alignments
- Try to maximize the amount of ink that the antialiasing will use for your shape at certain key pixels.
- Corners, ends, bends, inner lines.
- This means putting as much of the shape as you can within one square pixel, to make that pixel as bright (or as dark) as you can
You can have more than one grid active at a time in Inkscape. Choose File → Document Properties in the menu, click on the Grids tab in the dialog that appears, and click on New. You can then set the origin, spacing, and colour of the grid lines (or dots).
I like to work with an additional grid aligned to half-pixels for really fine work, and I edit the more normal one-pixel grid so it has its major lines either every 4 or every 8 pixel, and so that there's one major line intersection in the middle of the icon. The half-pixel grids allow me to lay out one-pixel width lines with the Bezier tool, and sometimes allow me to snap shapes to nice points when downscaling.
For the 22 pixel icon in the example above, I've se the origin of pixel-aligned grid by (-1, -1) and set its major lines to every 4 pixels so it's the same grid as the very similar 24 pixel icon. I don't offset the origin of the 1-pixel grid for any other size of icon because most don't need that trick, but I do use power-of-2 (doubling) major lines on everything so that I know where I am, and where a point is likely to end up if the icon was scaled down to a smaller power of two.
I tend to implement the half-pixel grid as an extra 1-pixel grid of dots, starting at an origin of (-0.5, -0.5), and with majors of (size of icon + 1) since they don't matter. That way, you see pixel centres as dots.
It's worth learning to spot the following angles in Inkscape and match them to their specific horizontal and vertical ratios. That's because regular antialiasing patterns look nicer in pixel renderings. Additionally, half-pixel grids sometimes have to be used for icon design, and having those switched on make this part harder to do visually. It's often easier than counting pixels to watch Inkscape's status bar for the angle of a straight line segment when you're creating it with the Bezier curve tool.
Ratio | Octant1 | Octant2 | Octant3 | Octant4 |
---|---|---|---|---|
1:1 | 45 | 45 | 135 | 135 |
3:4 | 36.87 | 53.13 | 126.87 | 143.13 |
2:3 | 33.69 | 56.31 | 123.69 | 146.31 |
1:2 | 26.57 | 63.43 | 116.57 | 153.43 |
1:3 | 18.43 | 71.57 | 103.43 | 161.57 |
1:4 | 14.04 | 75.96 | 104.04 | 165.96 |
Angles are in degrees, and I've omitted octants 5 through 8. Inkscape shows the latter 4 octants as negative angles with the same numeric values as the first 4. The ratio column is the ratio of the horizontal and vertical lines of a right angled triangle where the diagonal line you're drawing is the other line, the hypotenuse.
The table is organized by the first octant's angle, but the quality and usefulness of the line you get depends more on the largest term in the ratio column. The bigger the number, the harder it is to visually make out the line based on its antialiased form, and the more space you therefore have to give it. As a guide, avoid the ratios with a larger term of 4 unless the line is over 8 pixels long, and avoid ratios with a 5 or more as the larger term.