2

Why do jpeg files increase when they were converted from a gif file?

When I would convert a jpeg file to a gif, the file size would get smaller. However, converting the gif file to a jpeg would make the file size bigger than the original jpeg image.

2 Answers 2

2

Because you are potentially dithering the image, and a dither adds more information.

My explanation about compression.

"Imagine you have a gradient, from left to right, from white to black."

That is it. I just told you the compressed version.


Here is the uncompressed version:

"One pixel white. Next pixel not as white, next one a bit darker, next one a bit darker than before, next one...

On the second row. First pixel white, next pixel..."


Now, A gif image dithers the colors to emulate a gradient.

"First pixel white, second pixel a little gray... Next pixel... Ouch... as I do not have another gray, lets put a white pixel again to emulate a lighter combination of the gray pixels around me".


When you convert the image again to JPG... You do not have a gradient anymore you have the mess the other dude... I mean the GIF Made:

"First pixel white, second pixel a little gray... Next pixel... Ouch... that dude made a mess of the file... Ok, let's copy that mess... Second pixel little gray, next pixel white..."


So. Please STOP converting to GIF. Do not use it. The only valid case to use a GIF on the XXI century is an animated GIF.

Understand the file types needed for website design.

  • PNG for flat images or transparent ones.

  • JPG for photos.

  • SVG for vector shapes.

  • GIF for animated images. Flat design strongly recommended.

  • MP4 for video.

  • PNG and SVG images for animation via CSS, or Javascript.

1
  • 1
    THIS. Oh, SO this. So well said. Please leave this up so I can re-post, re-blog and use as a concept-hammer for file-format whack-a-mole discussions with clients and other folks! May 8, 2019 at 17:20
0

TLDR: Because GIFs use fewer bits of data per pixel to encode an image, only 256 colours max (Indexed colour), and to achieve the illusion of more colours or less banding, must utilize dithering.

It takes 24 bits of data to describe the colour of each pixel in RGB colour images such as JPEGs, but only 8 bits of data to describe the colour of each pixel in Indexed colour images such as GIFs.

It's actually a little bit more complicated than that, because JPEGs also employ a kind of lossy compression which can help keep the file size down significantly, and GIFs also contain data to encode the colours of the palette which they utilize. Also GIFs can be, and often are animated, which means they can also contain many frames which can make file sizes fairly large.

But basically it comes down to this:

GIFs = 256 colours max

JPEGs = 16,777,216 colours

To get all those extra colours JPEGs are capable of, you need lots of data, and lots of data means larger file sizes, and to keep file sizes down JPEGs rely on compression. As to differences in file size between a JPEG converted from a GIF compared to an original JPEG, it's because of the dithering used in GIFs which @Rafael has already explained. It adds more information/detail to the file, making JPEG compression less effective, resulting in larger than expected file sizes.

1
  • I realise now this is essentially the same answer as Rafael in some ways, but I thought it important to mention the difference between RGB and Indexed colour which lies at the root of the problem.
    – Billy Kerr
    May 8, 2019 at 23:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.