The Compromise of the Jpeg Format

As mentioned in the digital formats blog last week, each time you edit and save a jpeg file a process takes place that aims to reduce the size of the resulting file. This entails making some approximations about the content (the colour) of some pixels. Repeatedly saving a jpeg file will, therefore, degrade its quality.

Whenever you save a jpeg file, most programs will offer you a choice as to the trade-off you would like to make between the size and the quality of the file you are going to create. In the illustration here, I am choosing to save the best quality file, but it will be the largest. I could change my choice by moving the slider, entering a different number, or choosing a quality other than “maximum”. This illustration is from the Photoshop program. Different programs offer variations on this, but the result is always that you are making a choice between quality and size of file.

Jpeg quality versus file size

Note: merely viewing your jpegs (as opposed to editing and then saving them) will NOT degrade the image. And neither will time! Real, hard copy photographs do degenerate over time as chemical processes take their toll. Digital images on your computer will not suffer this fate.


Images as Email Attachments

If you are intending to send an image file as an attachment to an email then size matters. An image of acceptable quality saved as a jpeg could be 200kb or smaller, whereas the tif equivalent could be 20mb. The former would be perfectly acceptable as an email attachment, whereas the latter may not be delivered. As far as emailing jpegs is concerned, you can almost always save the jpeg at its highest quality and still have a file that will comfortably go through the email system. You can see in the first illustration that the file I am saving here would be 153.0k. This would be perfectly acceptable as an email attachment.

Quick reminder on file sizes: there are approx 1000kb in 1mb (one thousand kilobytes in a megabyte). An email attachment can be 5mb without causing problems and some email systems can handle attachments up to 20mb. Therefore, any file size that is expressed in kb (and is less than 5000kb) is less than 5mb. Therefore, any file size expressed in kb (provided that it is less than 5000kb) will be ok to send by email.

The Best of Both Worlds

If you only intend to edit a photograph once or twice then it’s probably OK (quality-wise) to save it each time as a jpeg. The quality will remain acceptable and it won’t cause problems by being too large. If, on the other hand, you are going to do a lot of editing, spread over several sessions, then it is worth getting to grips with how you can save an image in a “lossless” format such as tif or bmp, so that it doesn’t degrade each time you save it. When you have finished editing it you can save the final version as a jpeg so that you then get the benefit of compressing it without all the intervening stages of degradation. If you do this, by the way, you will finish by having a file in each of the jpeg format and the “lossless” format.

Whatever program you are using to edit your pictures, the way to save an image file in a different format is to find the command to “save as” (as opposed to the “save” command) and then look for an option to allow you to change the format. This illustration is from Photoshop:

Saving a file in a different format

In this instance, clicking on the triangle to the right of the “Format:” line offers many options for saving the file in a different format, including tif. When you have finished all the editing and want to create a final, smaller, jpeg file then just issue the “save as” command again and choose jpeg as the final format.

Zipping Image Files

Files can usually be compressed into smaller sizes by putting them into zip files (or other compressed formats such as rar). These can then be sent more easily through the email system. Zipping also has the advantage that only one file is sent, so it is easier to handle than trying to attach, say, 20 photograph files. The recipient then “unzips” the file back into its original components.

There is no reason why you cannot put jpeg files into zip files, but you won’t save much space. The jpeg has already been optimised, so the process of “zipping” it won’t squash it much more – if at all. Zipping “lossless” files (such as tif files) will reduce the overall size considerably and won’t compromise the quality of the image.

Having said all that, there are now many alternatives for showing other people your digital photographs that don’t involve trying to send them through the email system, so if you regularly send lots of images it’s worth considering them. These alternatives include posting images on your social media page (eg Facebook), storing them online on Microsoft’s Skydrive system or Kodak’s online photograph album system, or even creating your own photo website.

There are lots of other aspects of digital images that we could look at, so I think we will be returning to this subject before very long.

In the meantime, you can find more information on jpegs here.

There are two main ways that a digital file can store information about an image:

Vector images are made up of independent objects (eg circles, arcs, squares). Each of these objects is defined in terms of mathematical relationships and instructions as to how to create it. A square, for example, is defined by where it is placed on the image, the length of a side in relation to the size of the entire image, the thickness and colour of the defining edges and so forth. This sounds complicated when explained in words but, in fact, the size of images made up of vector shapes is typically much smaller than an equivalent bitmap file (see below). This is because it is not the image itself that is stored – just the instructions necessary to re-create it.

Zombie - created as a vector graphicThe other main feature of a vector graphic (or image) is that it is “resolution-independent”. If you print a vector image the size of a postage stamp, its sharpness will be the same as if you printed it to fill a whole A4 page. Vector graphics are used in situations such as computer-aided design where images are made up of individually created elements and where sharpness and clarity at large sizes are important. Unfortunately, vector graphics won’t work for us in a lot of situations because the image (eg a photograph) can not easily be broken down into objects that can be defined geometrically and mathematically.

The image of the zombie was created as a vector image (source).

Bitmaps or raster images
are the more familiar format of graphics file for most people. In a bitmap file the image is composed of thousands or millions of individually coloured rectangles or dots, each of which is a single colour. These are called “pixels” (a contraction of “picture elements”). Pixels can be seen in the enlarged section of Tate Modern on the bitmap here.

Bimap image showing pixels

There may be a choice of up to 16,777,216 colours available for each pixel. So, if you imagine a grid of 3000 pixels in one direction and 2000 pixels in the other, in which each pixel could be one of 16,777,216 colours, you are imagining what a bitmap image looks like. In this case, there would be 6 million pixels (3000 X 2000), so this is would be a “6 mega-pixel” image.

The problem with bitmap images is that they can be large – very very large – in terms of the space they take to store. It takes an awful lot of zeroes and ones to define 6,000,000 pixels when each pixel can be one of 16 million colours.

So, we can now say that the smaller, resolution-independent, type of image (ie the vector graphic) isn’t going to be any good to us if our images are, in fact, photographs (or anything else that can not be broken down into individual geometric “objects”). Therefore, we are usually going to be using bitmap (raster) images. This means that we are going to have to struggle with the play-off between the size of file that we create and the quality of the final image. It is largely to achieve the best compromise in this play-off that there exist several types of bitmap image:

Tif (or tiff) files tend to produce very large files because all of the information in each pixel is always retained (this is known as a “lossless” image type). This has advantages for quality but disadvantages for file size. It is often the preferred file format for people creating and editing images (including photographs) using photo editing software such as Photoshop.

Gif and png files (pronounced “gif” or “jif” and “pee en gee” respectively) are graphics formats producing very small files. They are mainly used for images on web pages. The small file size is achieved by reducing the number of different colours in the image to the minimum necessary to create that image at an acceptable quality.

Jpg or jpeg files (pronounced “jay peg”) are the most favoured for finished photographs. Almost all digital cameras will create jpg files (although a lot will also create other formats). The advantage is that the file is compressed to be smaller. The price to be paid for this is that some loss of information (which translates into picture quality) will occur. This probably won’t be too serious to begin with, but if you repeatedly edit and save a jpg image then the quality will continue to degrade.

Raw is a “lossless” format produced by many digital cameras. However, there are lots of flavors of raw images so you may need the software provided with the camera to handle them.

Bmp (bitmap) is a Windows specification of a lossless file. Bmp files can be large but they have the advantage that they can be handled by almost all programs that need to deal with image files . And, yes, we do now have two different uses of the word “bitmap”. It is used synonymously with “raster” (as distinct from vector images) and is also used as the name of a specific Windows file format.

Apart from the image itself, most image files can also carry other information (called “exif” information or “metadata”) that can be used and displayed by image-handling programs. This can include, for example, the camera type, exposure information, date and time of exposure, and – somewhat controversially – the exact geographical location where the photograph was taken (known as “geotagging“).

Although I’ve tried to keep this simple, we’ve only scratched the surface (ha-ha) of digital photography by just looking at how digital images are composed and the main formats of files. Next time, I will look in more detail at jpgs as these are initially the most commonly encountered files in digital photography.

© 2011-2019 David Leonard
Computer Support in London
Privacy Policy Suffusion theme by Sayontan Sinha