Have you ever noticed that after you'd upload an image to your favorite social media site,
it sometimes doesn't look quite as good as you thought it would, specifically because
the image was compressed or it had its resolution lowered?
Well, naturally, it turns out that there are reasons that social media services do this,
as it's crucial for helping them manage the millions of images our selfie addicted society
is uploading every day. So how exactly do these large services get images to us quickly, and how are they making
improvements to try and keep the image quality as high as they can?
To answer that, we spoke with Nolan O'Brien at Twitter, and we'd like to thank him both
personally as well as Twitter itself for help with this episode.
Large services like Twitter face enormous challenges trying to get images to so many
different users. The images that go through Twitter's servers every day number in the billions with a B,
and they have to figure out how to quickly get them to their 330 million users, even
if those users are far away from Twitter's data centers. A large part of the solution is using content delivery networks, or CDNs, which are distributed
storage networks that you can learn more about here. This way, devices will have a semi-nearby server to pull images from.
But what about the images themselves? Well, Twitter uses both PNG and JPEG images.
Both are compressed, which saves bandwidth compared to using huge uncompressed images
that can easily take up around 35 megabytes if shot with a typical smartphone camera.
However, PNGs use lossless compression, meaning their higher quality but take up significantly
more space than a JPEG. Typically, Twitter will convert most images to JPEG if the PNG version has a high color
depth, meaning that if they support 16-bit or a little over 65,000 colors, which actually
isn't all that many considering modern displays support millions of colors.
Additionally, JPEGs that take up more than 5 megabytes are also reduced in quality.
But hold on a second, I use Twitter all the time and I think the images look pretty decent.
How do they pull that off using so much compression?
Keep in mind that Twitter still supports JPEGs up to about 16.7 megapixels, or about 4.2 megapixels
if you're uploading from mobile. And when this service has to reduce to JPEG quality, it does so by only about 15%.
Typically such a loss in quality isn't noticeable unless you're looking very closely, yet still
saves a significant amount of bandwidth. And this is especially true since phone screens these days are very high resolution, yet small
in size, so images can very easily be scaled down in resolution without a noticeable loss
in visual fidelity. Many phone screens only have one red or blue pixel for every green, so trying to show a
super high resolution photo on them would be a waste, as the phones can't even reproduce
them accurately. If you compare these images to original side by side on a high-res desktop monitor, you
may notice a difference. But for phone users who are often most impacted by speed constraints, the compression methods
we've mentioned so far are no-brainers. Of course, sometimes noticeable trade-offs, even on mobile devices, cannot be avoided.
Many people use social media services without fast connections, so if you're on a slow
connection, you might notice that Twitter uses progressive JPEGs, meaning that a low-quality
version will fully load first while you wait for the higher-res version, contrasting with
the slowly loading image from top down as you probably remember from the dial-up era,
if you're old. Then you have to factor in how people use many different devices, including some really
old ones. This is a big part of the reason you might have noticed that Twitter header images often
appear to be lower quality as they're capped at 500 pixels vertically to ensure that they
can be shown correctly on legacy devices.
But what about all the space these pictures take up on Twitter servers?
Well, it turns out that storage isn't all that difficult to expand, so the choices that
social networks make with how they process images has less to do with drive capacity
and more to do with how to use as little bandwidth as possible for the end user.
Who has an extra five seconds to wait for the next zesty Linus meme to load?
Am I right? Not me. So thanks for watching, guys. If you liked this video, give it a like, give us a subscribe, and be sure to hit us
up in the comments section with your suggestions for future topics that we should cover.