Why can’t JPEGS be transparent?

414 views

Why can’t JPEGS be transparent?

In: 1537

19 Answers

Anonymous 0 Comments

Because the image format doesn’t support it.
In order for an image to be transparent you need to encode in the image how transparent it should be. That is, for each pixel, in addition to knowing the red, green and blue values, we also need to know “how transparent is it”. That’s commonly referred to as “alpha”, and so the image has to store RGBA (or ARGB) pixels, rather than just RGB.

JPEG doesn’t do that. It only stores three color channels, red, green and blue. The image format doesn’t give us a way to specify how transparent each pixel should be.

(Edit: As many commenters have pointed out, JPEG images *don’t* actually store red/green/blue information — and for that matter, it also doesn’t store values for each distinct pixel. They store other information which can be used to work out red/green/blue values for each pixel)

Anonymous 0 Comments

Are you familiar with Morse code? Morse code has the entire English alphabet and some punctuation, but there’s no distinction between capital and lower case letters. That’s why old telegrams are written all capital letters.

If you send dot-dot-dot, it’s just “S.” Not big or small S, just “S.” A code for small S simply doesn’t exist. You could invent one, but then everyone else would have to agree on it, otherwise nobody would understand you.

The JPEG format is a way of turning pictures into computer data, just like Morse code is a way of turning words into dots and dashes. There are no rules in JPEG for transparency, just like there is no sequence in Morse code for lower case S. You could try to add transparency to a JPEG, but nobody else’s computer would understand it, just like nobody else would understand your made up Morse code for lower case S.

Anonymous 0 Comments

GIFs have up to 256 colors one of which can be set as transparent.

The standard for JPEG does not include designating a color as transparent, so none of the program that display or edit JPGs can do that.

If you wanted to do that you would have to modify the standard and get ever browser and image display and edit too to incorporate the changes.

Somebody already tried that a while back .jp2 files or JPEG2000 do support transparency. However neither Firefox nor Chrome support that format and neither do many other tools that you usually use JPEGs with.

JPEG XR is another JPEG based file format that includes transparency but it is a Microsoft made standard and not widely adopted outside of MS products.

PNG is a file format unrelated to JPG and it supports transparency and is supported by almost any modern software out there that deal with image files.

Anonymous 0 Comments

They can, if you use the correct variant of JPEG. The catch is that almost every computer program only handles the OG variant from 1992, which doesn’t have any way to record transparency, and doesn’t know anything about more recent versions.

A newer version called JPEG2000 came out in about 2000, which could do transparency, HDR, and it could do lossless quality and drawings as well as photos. It was a completely different file type, so you needed special software to open it or save it, and do anything with it. There were also tons of companies claiming that JPEG2k was based on their patented technology and were threatening to sue anyone that used JPEG2k. It was also super slow to save and open files which was a big problem on the computers of the time. As a result almost no one used it – just a few pro photographers and doctors.

The latest version of JPEG is called JPEG XT. This adds all the cool features of JPEG2k and more, and is also compatible with the old JPEG file format. Old software can open a JPEG XT file and get a standard JPEG quality image out. New software will get the enhanced version of the file with HDR, transparency and other features. The problem is that not much software is out there that can save this type of file and not much that can open the new features.

Anonymous 0 Comments

JPEG was originally intended to store digital photographs. Just like old photographs, there was never any notion of “transparent” for a photo. As a result, the people that wrote JPEG never included a transparency feature.

It’s not really something you can bolt on after the fact either, because the way the picture is shrunk down, the transparency information would need to have been worked into the mathematical approach for compressing the information (which would mean changing the way it worked). Since there were already other ways to save pictures with transparency information, nobody felt it necessary to make changes to JPEG.

Anonymous 0 Comments

Because the format format doesn’t support it, JPEG was designed for ‘real life photos’ like camera photos, it was not designed for stuff like digital art, clip art, etc… JPEG doesn’t have a transparent “alpha” channel.

For transparent images use the PNG format.

Anonymous 0 Comments

I’m on text to speech so there may be a lot of typos in this.

To have transparency you have to encode the data in the image. So for example let’s start with bitmap, the bitmap file format assigns a full length number to each pixel you see in an image. And this the number people are most familiar with, like the color azure is “007FFF”. And what you’re seeing in that display is the first two digits are an encoded value of 0 to 255 to represent a red scale, followed by blue and then green scale. I hope you’re with me so far, let’s move to the format known as GIF.

This format doesn’t assign a *full* number for each pixel but part of one in order to reduce file size since each frame of animation is saved as another full image. So instead each pixel can only be one of 256 different values with the first 255 are reserved for a color palette. And the 256th one is a 100% transparent pixel.

Moving to the PNG format they use a longer number to encode values. You have the same red, blue, green color scale seen in bitmap but now you have an extra two digits that track transparency. This allows you to set transparency from 0~100% on each pixel and te extra information creates a larger file size.

But the jpg format does not save individualized pixels. It is designed to compress an image down for very small bandwidth transmission back in the early stages of the internet. So rather than saving an image pixel by pixel it actually saves a couple things into a few very small algorithms allowing it to use less space than bitmap.

Trying to keep this a little less detailed it basically saves a gray scaled image called luminous and then it saves two more images, one red scaled and one blue, reduced down to a quarter of the original size. Sectors are created and colors are blended together then ran through some mathematical processes to reduce their size even more. Every single time a JPEG is loaded this process is repeated in the reverse, unpacking the image rescaling back up. The process can even be set up to display a lower resolution image while the rest of its data is still being downloaded because you can send it complicated math problems instead of streaming pixels from top left to right and then down one row to repeat. And because this process rounds out colors you can get a lot of stray pixels. Those hard to read images on Facebook and such are a great example of this format’s weakness.

So going back to transparency in jpg. The base format just does not support it. You would have to tweak every algorithm it uses at every step, and to be honest the image quality of jpg wouldn’t benefit from transparency anyway which is why people use png instead. But the good news is there is a jpg format designed to support transparency and reduce some of the stray pixels. It’s design is mostly finalized but web browsers haven’t started pick up the format yet (if you were around for it, think Blueray vs HDDVD). In a few years it may become a standard format.

Edit – I finally got around to correcting some typos. It’s still long winded and probably a bit to detailed. Again sorry for the text to speech deal and I hope you got something out of this.

Anonymous 0 Comments

“Transparent” is a color.
JPEG don’t store that color,
because the standard designers don’t expect transparent to come out of a camera.

Anonymous 0 Comments

The modern way to encode transparency is to use 4 channels: 3 for colors (e.g. RGB or YCbCr) and 1 for degrees of translucency (the so-called alpha channel).

JPEG does not have this 4th channel. It uses [YCbCr](https://en.wikipedia.org/wiki/YCbCr).

The *old* way is to use a certain color (e.g. RGB=0,0,0, i.e. black) to be interpreted as invisible. That’s how GIFs work. Theoretically you could make a JPEG reader which does that.

GIF saves this color in its palette table, but JPEG doesn’t do that, so the reader would have to assume a certain color whether it makes sense or not. It’s not a deal breaker, though, there are some semi-reasonable ways, like checking corner pixels etc.

The biggest problem is JPEG compression blurs and replaces colors somewhat. Normally, it’s imperceptible when it replaces 0,0,1 and 0,2,0 with 0,0,0. With improvised transparency, a hole would grow or shrink when saved. Horrible.

Anonymous 0 Comments

Raster image files are stored as numbers. “Raster” is the name for images made of pixels, as opposed to vector which is geometric equations. Each individual pixel has a value for red, green, and blue. JPEGs only store these 3 color channels. Files like PNGs support a 4th channel called “alpha”, which contains a value for transparency for each pixel as well.

The JPEG format was developed for digital photography, which of course would not need a transparency channel.