The Definitive Guide to Optimize Images for The Web (And, Online Tools To Work With Images)

A quality website is a website that loads fast. Readers don’t like to wait, and it’s also no secret that page loading time is playing a very important role in the way how Google is ranking websites. And when it comes to page loading time, images and how optimized they are is very important. Here’s a definitive guide on how to optimize images for web as well as a few extra other techniques and guidelines.

Use The Right Image Format

The 3 most common file formats for images on the web are .jpg.png and .gif. Here’s a brief summary of each image format and when you should use it.

  • png: Use png images if the image has text in it, or if you need a transparent background.
  • gif: Use gif for very small images such as a 5*5px background tile.
  • jpg: Use this format for displaying photos, illustration images, etc.

Use Thumbnails Instead of HTML Resizing

HTML and CSS offers you the possibility of resizing images by specifying the desired width and height. While this is a useful feature, the image isn’t actually resized, it’s only displayed at a smaller size. You want to display a 500px width image? Then, resize your original image to 500px and display the resized version instead of the original.

If you’re using WordPress, the upload tool automatically resizes any uploaded image to various sizes (original, medium, thumb, etc) so you should always choose the appropriate size.

On php-based websites, there’s many different libraries that allow you to easily generate thumbnails on the fly. ImageMagick is one of the most popular.

Use CSS3 Effects Instead of Images

Need a gradient or a fancy text effect on your website? Don’t use images! The CSS3 specification allows you to add lots of visual effects. One of my rules of thumb when it comes to web design and development is to avoid using images as much as possible.

In other words, if you can do something using CSS, do it with CSS, not images. There’s tons of things that you can do with CSS3 instead of using images, and your website will be faster.

Use Web Fonts Instead of Encoding Text in Images

In late 2015, I still see lots of people encoding text in images. This is definitely bad. In 90% of case, you can instead use a webfont and CSS. Webfonts are faster to load than a whole bunch of encoded text images.

Using webfonts is super easy. In order to ensure a good cross-browser compatibility, you need to have the font you wish to use in the following formats: .ttf.woff.svg and .eot. If you only have one of those file formats, there’s a super useful online tool to help, the Fontsquirrel webfont generator.

Drop your fonts somewhere on your web server, then add the following on your .css file:

@font-face {
  font-family: 'Tagesschrift';
  src: url('tagesschrift.eot'); 
       url('tagesschrift.woff') format('woff'),   
       url('tagesschrift.ttf') format('truetype'),
       url('tagesschrift.svg#font') format('svg');

Once done, you assign the webfont to an element using the font-family property:

p {
    font-family: "Tagesschrift", Georgia, Serif;

Make Use of Photoshop’s “Save For Web” Tool

When it comes to web design, Photoshop is by far the most popular program, and most of you are probably using it. Despite its popularity, a lot of users never use the “Save for web” feature. It’s a shame, because this function allows Photoshop to provide the user presets to save a image in order for it to be displayed on a website.
Basically, if you’re intending to display and image on your website, use Photoshop’s “Save for web” function. Always.

If you don’t have Photoshop, don’t worry. You can use Optimizilla, an online image optimizer. Prefer using an app? Then I recommend RIOT.

Use Caching Techniques to Display Your Images Faster

Although this isn’t really an image optimization technique itself, caching your images is an overall good practice and will display your images faster to your returning visitors.

Here’s a ready-to-use code snippet that will cache various filetypes (images, and also other kind of documents like pdf or flv). This code has to be pasted in your website .htaccess file. Make sure you have a backup of it before applying this technique, just in case something goes wrong.

# 1 YEAR
<FilesMatch "\.(ico|pdf|flv)$">
Header set Cache-Control "max-age=29030400, public"
# 1 WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
# 2 DAYS
<FilesMatch "\.(xml|txt|css|js)$">
Header set Cache-Control "max-age=172800, proxy-revalidate"
# 1 MIN
<FilesMatch "\.(html|htm|php)$">
Header set Cache-Control "max-age=60, private, proxy-revalidate"

Online Tools To Work With Images

Using WordPress? Install the WP Smush plugin

If you’re using WordPress, you can save a lot of time by simply installing a plugin that optimize your images. I’ve been using WP Smush. It works like a charm: install the plugin, then upload your images normally. WP Smush takes each image you’re uploading and optimizing its size with no compromise on the quality. Results are impressive: images can be reduced up to 80% in size.

There’s also a “pro” version of the plugin, called WP Smush Pro. I haven’t tried it yet but the extra features are very appealing: optimization of images up to 32mb (WP Smush is limited to 1mb), bulk optimization of all your images with one click, even better compression, and so on.

PhotoShop Online Tools

When it comes to image editing, Adobe Photoshop is definitely the most popular software. Adobe launched a light version of Photoshop which is available online. The online app is quite powerful and has many features. Unfortunely you have to register to use Photoshop online.

Visit PhotoShop Online Tools

Pixlr express is a simple but powerful app which allow you to resize images, add effects, borders, watermarks, etc. The app is free and does not require registration.

Visit Pixelr Express

Aviary Phoenix

Developed in Flash, Aviary Phoenix is a super-complete and free online image editor. A real “light photoshop” that you can access from any computer, without any registration.

Visit Aviary Phoenix

Improvise Solutions