An Overview of Scaling SVG vs. Bitmap (JPG, PNG) Images
Tags: webdev, frontend, tutorial
Published: 2024-02-14 13:00:00

Having looked at the basics of [SVG](https://webdeveloperdiary.substack.com/p/svg-an-introduction-vs-bitmap-formats) and bitmap formats (like [JPG and PNG](https://webdeveloperdiary.substack.com/p/jpg-vs-png-pros-and-cons-when-building-apps)), we now have a rough idea of their pros and cons. In this article, we’ll look at another important factor that sets these formats apart: scalability.

## Getting Things Pixel Perfect – Scaling Bitmaps

A bitmap format represents an image as a series of pixel colour values. Each pixel is a separate entity, and we have independent control over its value. This works to our advantage in images where colours and textures blend smoothly. But when we want to scale an image (to make it either larger or smaller), the nature of being a grid of colour points has its disadvantages.

To explain why, consider Image 1. When we look at it, we see a diagonal line going through the centre of a rectangle. But as a bitmap image, it’s nothing more than a series of colour values.

![A diagonal line with rounded line endings inside a rectangle](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0lxwd8bmt7ds1kl01ycd.png)

<figcaption>
Image 1: A diagonal line with rounded line endings inside a rectangle
</figcaption>

Let’s say we wanted to double its size. As a grid of colour values, we have no concept of there being a line. Instead, we work at the pixel level and duplicate each one horizontally and vertically. And if we wanted to zoom an image to four times its original size, we’d replicate each pixel four times. And so on: we’re effectively increasing the size of each pixel in the image without adding to or enhancing any of its details.

After a certain point, this affects image quality. Image 2 shows the top right tip of the line at different zoom factors. Everything is smooth and sharp at 1x. The image starts to look blurry at 2x but isn’t too bad. At 4x the diagonal line starts to look like a series of steps, and this pixelation is even more apparent at 8x. (The pixel gridlines in the image are an overlay from [Affinity Photo](https://affinity.serif.com/en-gb/photo/) – the image editor I used while zooming into the image.)

![The top right tip of the line from Image 1 shown at 1x, 2x, 4x, and 8x zoom levels as a bitmap](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2gjmb87snpt2hdovudhr.png)

<figcaption>
Image 2: The top right tip of the line from Image 1 shown at 1x, 2x, 4x, and 8x zoom levels as a bitmap
</figcaption>

Pixelation is more noticeable with certain types of image content than others. But in general, it isn’t possible to scale a bitmap up too far without it become apparent.

## Plotting a Route – Scaling SVGs

SVG images define their content as shapes on a co-ordinates grid. Instead of a series of unrelated colour values, Image 1 would be represented as a series of lines and curves. Scaling an SVG involves multiplying the co-ordinates of its content by the zoom factor. As shapes are mathematically defined, we’re able to recreate them at any scale without any loss in quality.

![The top right tip of the line from Image 1 zoomed in as an SVG](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o2ypocxn4gzxis9czynx.png)

<figcaption>
Image 3: The top right tip of the line from Image 1 zoomed in as an SVG
</figcaption>

Image 3 shows the same tip of the line from Image 1, zoomed in as an SVG. Despite a greater scale factor than the 8x level shown in Image 2, the line ending is still smooth and rounded.

## Summary

A bitmap format like JPG or PNG represents an image as separate colour values, whereas SVG defines its content as shapes. This affects how scalable an image is.

When working at the pixel level, scaling an image up effectively means increasing the size of each pixel without being able to add more detail. At smaller zoom increases, this can cause an image to become blurry; at higher levels, pixelation becomes apparent and rounded edges become ‘stepped’.

Scaling an SVG involves applying a zoom factor to its content. As shapes are defined mathematically, this process causes no loss in quality; rounded edges won’t suffer from pixelation, even at high magnification levels.

---

Thanks for reading!

This article is from my [newsletter](https://webdeveloperdiary.substack.com/?sd=pf). If you found it useful, please consider subscribing. You’ll get more articles like this delivered straight to your inbox (once per week), plus bonus developer tips too!