How to use Image Scaling properly
I’ve worked with many designers and developers over the years and found that only of few understood a topic we all share, Image Scaling.
Image Scaling is the ratio an image should be to appear crisp and clean on a computer screen based on the screens Pixel Density. (<- Nifty video with more info)
Here is a table that shows what a properly scaled image should be. (Detailed explanation below)
More - Material Design Units and Measurements
Screen resolution: The number of pixels in a screen that can be shown. Associates a category that a given screen falls in.
dpi (dots per inch): How dense pixels are packed in an inch of the screen (Important if you are a developer).
m = medium, h = high, x = extra. (l or low dpi was a thing, but almost no screens fall in that category now)
Pixel ratio: The multiple of the size image you need to be using (Important for designers)
Image size (pixels): Example dimensions an image should be exported. (These dimensions should be the sizes you need for your project, and will probably be different than these)
For a real world reference, most computer monitors still fall in the mdpi screen resolution category, while most iPhones and Android Phones fall in the xhdpi to xxxhpdi screen resolution categories.
How do I use Image Scaling correctly?
1. Start by designing at mdpi as your base size.
Notice the pixel ratio is equal to 1.0. That means that this is your 1x image asset, and the math is easier to scale your image up (x2, x3 etc), compared to scaling your image down. (/0.5, /1.5, etc).
If you are using Sketch, check out the “Make Exportable” feature! This does most of the work for you ;)
2. Design in Vector (if possible).
Vector assets allow for an unlimited number of pixel densities and are very easily able to scale up or down.
3. Know where your image will be in the user interface and set the size accordingly.
As a general rule of thumb, avoid using images that are odd sizes (i.e. 23x23) instead use even size images (i.e. 24x24), and if you are designing vector icons, align the anchor points to a specific x / y position. This will prevent your image from blurring.
4. Know what file type to use and when to use it.
PNG: Small to large sized images with any number of colors. PNG are nearly uncompressed images and have the highest quality.
JPG: Large to massive images. JPGs are compressed and do not have the highest quality and will keep file size down when exporting.
SVG: Use these for icons or images with very few colors. These are special because they will automatically scale and do the equations for you. Just make sure you are designing them at mdpi.
GIF: Avoid using these if possible. If you need an animation, consider using 1 PNG and animating it in code, or making an animated SVG.
1. Allow your code to handle images of multiple densities.
Web devs: use src-sets and media queries.
Android devs: use all the drawable folder
iOS devs: use the asset folder
2. Use Vector Assets if possible.
Web devs: SVGs are supported
Android devs: Vector Drawables are supported
iOS devs: PDFs are supported
3. Set the images to the correct size for your views.
Allow your views to either resize themselves automatically based on the size of the images, hard-code the view size to the exact size of the image asset, or using set the image scaling to show the image at the proper quality. This will ensure you are not stretching or squishing the image to a size it is not supposed to be.
4. Consider compressing your PNGs and JPGs for performance.
Check out https://tinypng.com/. This will increase load times of the images in your apps and cut back on overall size of your apps.
As mentioned in some tips above, you can avoid having to deal with density all together and use a vector based solution like SVGs (scalable vector graphics), Vector Drawables and PDFs. These are only usable for icon-like designs with very limited color. Some added benefits of using vector images is that you only need to maintain 1 asset, and the file size is very small!
Image Scaling is a topic that designers and developers both need to understand. And if you can bridge the gap from design to development, together we can save the world from pixelated images!
~ Mike, Product Designer & Front-end Developer