Sub topic 11
Choosing the right model for the job
This chapter assumes you already know how a raster image stores a grid of pixels and how a vector image stores paths, points and styles. It also assumes you know that raster images are tied to a pixel size and vector images scale freely. The earlier chapters explained those mechanics. This one turns them into a repeatable way to decide which model to use.
Start from the content, not the file format
Beginners often ask "should I save this as PNG or SVG?" That question comes too late. The format follows from the model, and the model follows from what the image contains and what must happen to it.
Ask two questions in order:
- Was the image captured or constructed? A camera or scanner captures continuous variation in light, so the result is naturally a grid of samples. A designer constructs images from shapes, lines and text, so the result is naturally a list of shapes.
- What has to happen to it later? It may be scaled to unknown sizes, edited shape by shape, recolored, animated, or printed on a large surface. Each of these favors one model.
If both answers point the same way, the choice is easy. If they conflict, you need one of the hybrid approaches described later.
The decision factors
| Factor | Favors raster | Favors vector |
|---|---|---|
| Source | Photos, scans, screenshots, painted textures | Logos, icons, diagrams, charts, typography |
| Tonal complexity | Millions of subtly varying colors, soft shadows, noise | Flat color areas, clean edges, limited gradients |
| Size requirements | One or a few known output sizes | Many sizes, or sizes not known in advance |
| Editing | Pixel-level retouching, painting, filters | Moving, resizing and recoloring individual shapes |
| File size | Grows with pixel count, whatever the content | Grows with the number of shapes and points |
| Interactivity | Rarely needed | Styling and animating parts with CSS or scripts |
| Output device | Screens at a known size | Print, signage, cutting machines, plotters |
Read the table as a set of tendencies, not a vote count. One strong factor can outweigh several weak ones. A product photo must be raster even though you want it at many sizes, because no practical vector can reproduce it. You solve the scaling need by exporting several raster sizes.
Walking through common jobs
Logos
A logo is reused on business cards, websites, vehicles and billboards. Its size is unknown when you create it, and its shapes are simple. Keep the master in vector form. Export raster copies (PNG, for example) only for places that demand them, such as a social media profile picture. Always keep the vector master, because you can make a raster from a vector but cannot reliably go back.
Photographs
Photos are raster. Choose the pixel dimensions for the largest size you will actually display, then compress. A vector trace of a photo either loses detail or becomes enormous, because every tiny color region needs its own shape.
Icons
User interface icons are usually vector. They are small, simple, need to look sharp on screens with different pixel densities, and often need to change color for states such as hover or disabled. An inline SVG can inherit the surrounding text color:
<button type="button" aria-label="Search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"
fill="none" stroke="currentColor" stroke-width="2"
stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">
<circle cx="11" cy="11" r="7"/>
<path d="M16 16 L21 21"/>
</svg>
</button>The currentColor keyword takes the color of the button's text. This works only when the SVG is written inline in the HTML. If you load the same file through an <img> element, the SVG cannot inherit page styles.
Illustrations
Illustrations depend on style. Flat, geometric, or line-based work suits vector. Painterly work with brush texture, grain or soft blending suits raster, because those effects are hard to describe as clean paths. Many illustrators build the shapes in vector and add texture as a raster layer.
Screenshots and pixel art
Screenshots are records of what a screen displayed, so they are raster. Use a lossless format, because lossy compression smears the sharp text edges. Pixel art is raster by definition, since each pixel is a deliberate choice. Scale it only by whole-number multiples, such as 2x or 4x, and use nearest-neighbor scaling so the pixels stay crisp.
Print pieces
For a print piece such as a poster or brochure, put text and logos in vector form so they print with sharp edges at the printer's full resolution. Place photos as raster images with enough pixels for the printed size. Page layout programs and PDF files mix both models without trouble. Preparing the files for delivery is covered in the chapter on web and print.
A small checklist you can run
The decision logic can be written down. This function encodes the factors above. It is a teaching aid, not a replacement for judgment, but writing it forces you to name each factor.
def choose_model(
captured: bool,
needs_arbitrary_sizes: bool = False,
needs_shape_edits: bool = False,
has_painterly_texture: bool = False,
) -> str:
"""Return 'raster', 'vector' or 'hybrid' for an image job."""
if captured:
return "raster"
if has_painterly_texture:
# Shapes plus a raster texture layer is the usual compromise.
return "hybrid" if (needs_arbitrary_sizes or needs_shape_edits) else "raster"
return "vector"
jobs = {
"product photo": dict(captured=True),
"company logo": dict(captured=False, needs_arbitrary_sizes=True),
"toolbar icon": dict(captured=False, needs_arbitrary_sizes=True),
"textured poster art": dict(
captured=False, has_painterly_texture=True, needs_arbitrary_sizes=True
),
"one-off painted banner": dict(captured=False, has_painterly_texture=True),
}
for name, args in jobs.items():
print(f"{name}: {choose_model(**args)}")Running it prints raster for the photo, vector for the logo and icon, hybrid for the textured poster art, and raster for the painted banner.
Edge cases and traps
Vector is not always smaller
A simple logo is tiny as SVG. A vector made by tracing a photograph can contain tens of thousands of paths and become far larger than a compressed JPEG of the same picture. It also renders more slowly, because the browser or app must draw every shape. File size in vector grows with complexity, not with display size.
A vector file can contain raster data
An SVG, PDF or EPS file can embed a bitmap. A file with the .svg extension is not automatically resolution independent. Open it in a text editor or an editing tool. If you see an <image> element holding a base64 string, that part will pixelate when enlarged.
Text needs care
Text in a vector file depends on fonts. If the viewer lacks the font, it substitutes another. For logos and artwork you send to others, convert the text to outlines (shapes) so it looks the same everywhere. For web pages, keep text as real text, not as an image of text, so it can be searched, selected and read by screen readers. Do not use a raster image of text for body copy.
Small sizes can favor raster
At very small sizes, such as a 16 by 16 pixel favicon, a vector scaled down can blur across pixel boundaries. A designer may draw a hand-tuned raster version for each small size, a practice called pixel fitting. Vector scaling is mathematically correct but does not guarantee the sharpest result on a pixel grid.
Effects can break the vector model
Blurs, drop shadows, and complex blend modes are rendered as pixels at some stage. Some tools keep them live and re-render them at each size. Others flatten them into raster when exporting. Check the exported result at the largest size you will use.
Do not choose by file extension alone
Both models can look identical on screen at one size. Judge by how the file behaves when enlarged to several times its size and when you select individual parts of it.
Choosing for the same asset in several places
One brand asset often needs more than one form. A practical set for a logo might be:
- A vector master (SVG, or the design tool's native file) for editing.
- An SVG for use on the website, served at any size.
- A PDF or EPS for printers.
- PNG exports at fixed sizes for places that accept only raster images.
On the web, you place SVG and raster files with the same element, so you can swap one for the other without changing the page layout:
<img src="logo.svg" alt="Company logo" width="120">
<img src="photo.jpg" alt="Mountain lake at sunrise" width="600" height="400">Giving both width and height for the photo lets the browser reserve space before the file loads, which prevents the page from shifting.
Summary of the choice
Use raster when the image is a record of the real world or depends on continuous tone and texture. Use vector when the image is built from shapes and must stay sharp, small in file size, or editable at any scale. Use both when the artwork needs shapes and texture, and keep the source files so that each output can be regenerated.
Exercise
A client sends a 400 by 400 pixel PNG of their logo and asks you to put it on a 3 meter trade-show banner. The PNG has hard edges and three flat colors. Which model should you use for the banner, what do you need to do, and why would simply enlarging the PNG fail?
Show answer
Use vector. Redraw the logo as vector shapes, either by tracing it (flat colors and hard edges trace well) or by asking the client for the original vector master. Enlarging a 400 by 400 pixel PNG to 3 meters would stretch each pixel into a large block or force the software to guess new pixels, so the edges would look blocky or blurry. A vector logo is described by shapes and scales to any size with sharp edges.
Exercise
You are building a website with a product photo gallery, a company logo, and a set of small interface icons that change color on hover. Assign raster or vector to each, and name one condition under which the SVG icons would not be able to change color from the page's CSS.
Show answer
The product photos are raster (for example JPEG or WebP, exported at the sizes displayed). The company logo is vector (SVG). The icons are vector (inline SVG). The icons cannot inherit or be styled from page CSS when they are loaded through an img element, because the SVG then renders as a separate image. Inline SVG, which uses currentColor or CSS rules, can change color on hover.