Compare bmp and jpg file sizes. Which image format is better - png, gif or jpeg? Pros and cons of JPEG

Do you know the difference between JPEG, GIF, PNG and other image formats? When should you use one or another format, or which is best for saving photos? Below you will find answers to all these questions.

In contact with

Lossy/lossless data compression algorithms

First of all, you need to understand the difference between lossy and lossless data compression algorithms. Lossless compression is a method of image compression that maintains its quality regardless of how many times the file is compressed and restored.

When using lossy compression, the image quality will decrease every time the file is compressed/decompressed. One of the undoubted advantages this method lies in the possibility of a higher degree of compression. For storing and editing photos, lossless compression is more suitable, however, if you need to send the image via e-mail or publish it on the Internet, it is better to use the second method.

.RAW

A file format containing raw information coming directly from the sensor of semi-professional and professional cameras. These files are not processed by the camera processor and contain all captured information in “raw” form. The size of such files can exceed 25 MB. RAW files are great for editing, but due to big size storing them is not very convenient.

.JPEG (JPG)

This is perhaps the most common graphic format. It is usually used to publish photographs and images with text on the Internet. JPEG is a TrueColor format, which means it can store images with a color depth of 24 bits/pixel. This format can display more than 16 million colors.

JPEG has earned its popularity due to its flexible data compression capabilities. If necessary, the image can be saved from high quality. When using a lossy compression algorithm, image quality is lost every time a file is saved. Below are JPEG images in high, medium and low quality.

High quality JPEG (100). Size 113 KB

JPEG with medium quality (50). Size 59 KB

Low quality JPEG (20). Size 27 KB

.GIF

The GIF (Graphics Interchange Format) format does not please with color depth (8 bits). It can store lossless compressed images in a maximum of 256 colors. One of the features of GIF is its support for animation.

.PNG

This format was developed as a replacement for GIF. PNG stands for Portable Network Graphics. Unlike GIF, PNG has support for transparency gradations due to an additional alpha channel. Typically, transparency is indicated by a checkerboard background, as seen in the image below.

Externally, files in PNG format are practically no different from JPG images. PNG compresses data without loss. If transparency is important to you, it is better to choose this format.

When creating websites at the layout stage, there is always the task of choosing one or another format for storing images. Images can be saved in any PNG, JPEG, GIF and dozens of other formats, but what format should you choose to transfer? better quality with the minimum size of the resulting image file?

Which file format should I choose?

GIF format limited to 256 colors. This is a lossless format and when used, minimal image compression is achieved. The GIF format supports animation (the only one of all formats) and transparency, but translucent images cannot be saved in it. Due to the peculiarities of the algorithm, it compresses images very well, which have vertical lines (for the web, for example, these can be vertical dividing stripes, single-color icons, graphic dots, etc.). It can be used to store drawings, text and symbols graphics in a small file size.

PNG format is a format in which compression occurs without loss. In this format, each pixel has 3 color channels (RGB - red, green, blue), thereby realizing full-color image formation without distortion. The PNG format may be superior in color quality to JPG, but the file size will also be larger. The PNG format supports different levels of transparency (translucency). Due to the peculiarities of the algorithm, it compresses images very well that contain horizontal lines. And when the task is to choose to save a file in GIF or PNG format, for cases where the picture consists of primitive lines, you should pay attention to the position of these lines - i.e. You should save images with vertical lines in GIF format, in PNG – horizontal. PNG is good choice for storing drawings, text and iconic graphics in a small file size.

JPG format is a format that suffers from color loss. The algorithm for working in this format is such that it compresses images with gradients very well (the colors of the first pixel in the gradient and the last are saved, and when displaying the image, all intermediate colors between these points are calculated), which makes it useful for storing images in a smaller size than in BMP format. It is better to save photographs, overflows, logos, backgrounds, etc. in JPG format.

Thus, when developing websites, you can achieve very good results in speed due to the right choice image storage format.

Now the jpeg format has a leading position. Thanks to its ability to compress photographs and color images several times, it is ahead of the gif and png formats in terms of minimum weight, and bmp is still “grazing the rear”.

Nowadays it is probably impossible to find a web page on the Internet without some photographs or pictures on it. Today this has become the norm when laying out any web pages, because pictures enliven, decorate, complement the main content of sites and are successfully used in all areas of the web. By the way, the first browser that could display graphics was Mosaic (mosaic), which appeared almost simultaneously with the advent of the hypertext markup language Html.

Nowadays, almost all browsers support the three main raster graphics formats used for the web - Gif, Png and Jpg. Historically, gif was the first to appear, and it was with its help that images and media information could be added and displayed in the first browsers. When creating it, the developers focused on minimizing the size of the saved image.

After all, at that time the speed of the Internet was so low, and so that loading images did not take “forever,” a special “graphic exchange format” was developed and applied (this is what the abbreviation GIF stands for).

The special thing about Gif is that it can include a palette of only 256 colors. Those. An image converted to this format will always contain a maximum of 256 shades, with all other colors created from a mix-in. But it is precisely because of this very mixing that various unexpected artifacts appear when converting full-color photographs into GIF. Because of this obvious and significant drawback, jpeg and png are increasingly being used to display full-color images and photos on website pages.

But gif is still popular in the web industry for one simple reason - it supports animation, the only one used on the web. Animated emoticons and avatars, postcards and banners are the result of the GIF format. True, flash technologies are no less popular now, but due to their simplicity, gif is a favorite among webmasters, especially beginners.

The essence of this animation is that the GIF container contains not one image, but several at once, and the time after which these images will replace each other is also written there. In this case, it is possible to loop the animation and then after the last frame the display of the first one will begin again. Today on the Internet there are many specialized editors in which you can create Gif animation yourself.

Gif can also support a primitive way of generating transparency for created images. Why primitive? Yes, because GIF supports only two transparency values ​​- transparent or opaque, without any intermediate states that can be achieved by using alpha channels in Png formats.

Because of this, difficulties arise with displaying smoothly changing levels of transparency, so everything related to high-quality transparent backgrounds for images is the prerogative of Png. Almost all images from transparent background, which we can find on the Internet, have the extension png.

There are several variations of Png, each of which is designed to perform its own tasks:

Png 8 - here, by analogy with Gif, when saving a photo in PNG 8, only 256 colors will be used, therefore the results of image compression in these two raster graphics formats will be almost identical. Just like in Gif, transparency is supported here, but with an alpha channel.

Png 24 - here, for each pixel of the photo, three color channels of 8 bits each (8*3=24) are allocated, thereby realizing full-color image formation without distortion. The quality of color display is superior even to Jpg, but it will be heavier in weight.

Png 32 - here three color channels are responsible for the formation of a full-color image, and the fourth is allocated separately to form an alpha channel, which allows you to use Png 32 to obtain pictures with a transparent background. In Png 32 you can choose any change in the degree of transparency, thanks to which such images will look equally good on all web pages with any background.

Now let's summarize all the information and draw some conclusions.

There are two types graphic files, these are raster and vector, which have different formats.

  1. raster graphics files correspond to the formats *.bmp, *.tif, *psd, *.gif, *.png, *.jpg;
  2. vector graphics file corresponds to the formats *.wmf, *.eps, *.cdr, *.ai

Knowledge of file formats is the basis for working with digital photographs because they determine how the information is stored in the file (raster or vector), as well as the form in which the information is stored (the compression algorithm used). Compression is used for raster graphics files, since they are usually quite large. Compressing graphic files differs from archiving them using archiving programs (gag, zip, arj, etc.) in that the compression algorithm is included in the graphic file format.

Basic graphic file formats

RAW

Translated from English - raw. The format used in the photo processing process contains raw information that comes directly from the camera sensor and does not have a clear specification. These files are not processed by the camera's processor (unlike JPG) and contain original shooting information. RAW can be compressed without losing quality. Unlike JPG, which was processed in the camera and already saved with data compression, RAW gives the widest possibilities for processing photographs and preserves maximum quality.

In other words, under RAW format refers to data obtained directly from the matrix without processing.

Different camera manufacturers use different algorithms to create RAW in their cameras. Each manufacturer comes up with its own resolution for its RAW file - NEF, NRW - Nikon; CRW, CR2 – Canon.

JPEG (or JPG)

This is the most common graphics file format. JPEG has earned its popularity due to its flexible data compression capabilities. If necessary, the image can be saved from maximum quality. Or compress it to the minimum file size for transmission over the network. When saving a JPEG file, you can specify the degree of quality, and therefore the degree of compression, which is usually specified in some conventional units, for example, from 1 to 100 or from 1 to 10. A larger number corresponds to better quality, but the file size increases. Usually, the difference in quality between 90 and 100 is practically not perceived by eye.

JPEG uses a lossy compression algorithm. What does this give us? An obvious disadvantage of such a system is the loss of image quality every time a file is saved. On the other hand, image compression simplifies data transfer by 10 times. In practice, saving a photo with a minimum degree of compression does not result in any visible degradation in image quality. That is why JPG is the most common and popular format for storing graphic files.

TIFF (Tagged Image File Format)

TIFF format is a format for storing raster graphics. It was originally developed by Aldus in collaboration with Microsoft for use with PostScript. It allows you to save photos in various color spaces (RBG, CMYK, YCbCr, CIE Lab, etc.) and with high color depth (8, 16, 32 and 64 bits). TIFF is used in scanning, faxing, OCR, printing, widely supported graphic applications. It is possible to save an image in a TIFF file with or without compression. Compression levels depend on the characteristics of the image being saved, as well as on the algorithm used. Unlike JPG, a TIFF image will not lose quality every time the file is saved. But, unfortunately, it is precisely because of this that TIFF files weigh many times more than JPG.

PSD (Photoshop Document)

Photoshop Document (PSD) is an original raster format for storing graphic information using lossless compression, created specifically for the program Adobe Photoshop and supporting all its capabilities. It allows you to save raster image with many layers, any color depth and in any color space. Most often, the format is used to save intermediate or final results of complex processing with the ability to change individual elements. PSD also supports compression without loss of quality. But the abundance of information that a PSD file can contain greatly increases its weight.

BMP (Bit MaP image)

Bit MaP image (BMP) is a universal raster graphics file format used in operating system Windows. This format is supported by many graphic editors, including Paint editor. Recommended for storing and exchanging data with other applications. The BMP format is one of the first graphic formats. It is recognized by any program that works with graphics. BMP stores data with color depth in this format from 1 to 48 bits per pixel, maximum image dimensions 65535x65535 pixels. On this moment BMP format practically not used either on the Internet (JPG weighs several times less) or in printing (TIFF copes with this task better).

GIF (Graphics Interchange Format)

format for storing raster graphics. The GIF format is capable of storing compressed data without loss of quality in a format of up to 256 colors. Includes a lossless compression algorithm that allows you to reduce the file size by several times. An image in GIF format is stored line by line; only the format with an indexed color palette is supported. Recommended for storage; images created programmatically (diagrams, graphs, etc.) and drawings (such as appliqué) with a limited number of colors (up to 256). Used to place graphic images on Web pages on the Internet.

PNG (Portable network graphics)

A raster format for storing graphic information using lossless compression. PNG was created to both improve and replace GIF format graphic format, which does not require a license to use. Unlike GIF, PNG has alpha channel support and the ability to store an unlimited number of colors. PNG compresses data without loss, which makes it very convenient for storing intermediate versions of image processing. Used to place graphic images on Web pages on the Internet.

JPEG 2000 (or jp2)

A graphic format that, instead of the discrete cosine transform characteristic of JPEG, uses wavelet transform technology, based on representing the signal as a superposition of some basic functions- wave packets. As a result of this compression, the image is smoother and clearer, and the file size compared to JPEG with the same quality is reduced by another 30%. In simple terms, for the same quality, JPEG 2000 file size is 30% smaller than JPG. At strong compression JPEG 2000 does not break the image into squares that are characteristic of the JPEG format. Unfortunately, at the moment this format is not very widespread and is only supported Safari browsers and Mozilla/Firerox (via Quicktime).

WMF (Windows MetaFile)

A universal format of vector graphics files for Windows applications. Used to store a collection of Microsoft Clip Gallery graphics.

CDR (CorelDRaw files)

Original vector graphics file format used in the processing system vector graphics CorelDraw.

AI (AdobeIllustrator files)

An original vector graphics file format used in the AdobeIllustrator vector graphics processing system.

EPS (Encapsulated PostScript)

The format of vector graphics files is supported by programs for various operating systems.

Here are almost all the most common ones graphic file formats, which a self-respecting photographer and designer should know.

JPEG and PNG are the two main image formats used on websites. In some cases it is better to use JPEG, and in others - PNG.

JPEG (aka JPG) is an image format that uses lossy compression and does not support transparency. Allows you to adjust the quality level of the saved image - when it is reduced, details are removed and noise is added to the image. However, the size becomes more compact. JPEG is optical for images with a large number of colors (for example, for photographs).

PNG 24 is an image format that works with full-color images, uses lossless and pose-free compression helps to maintain transparency. It is impossible to adjust the quality of saving in PNG 24, however, you can adapt to save my image to achieve the same -minimum file size: to do this, you can reduce the number of colors in the image. PNG 24 opti-ma-lens for images with a small number of colors (for example, for icons, diagrams and drawings). PNG 8 is a more compact format, but only suitable for images with a limited number of colors (256 - this is maximum).