Should I Save My File As a JPEG or PNG? How to Maximize Image Quality Online

Photoshop August 21st 2014 1:31 PM 9 Comments

_DSC6218-650w

Recently, I was planning to post a photo online and I wanted it to look its very best. The JPEG file format uses a lossy compression algorithm which means that some image quality degradation typically occurs when saving an image as a JPEG. The tradeoff for this loss of image quality is smaller file sizes and quicker downloading from the web. But I knew that the PNG file format uses lossless compression which means that there should be no loss of quality. Still, I wanted to be sure that this was the case, so I did a test in Photoshop.

Rainbow Test Image

Test image created in Adobe RGB (1998) color space and saved in PNG-24 format with an embedded Adobe RGB (1998) color profile

What I discovered surprised me—my test showed that there was a difference between my original image and the file I saved in the PNG file format. Further testing revealed the problem and confirmed that you can save a PNG with no loss of quality. I’ll demonstrate my testing technique and also give some tips on saving both PNGs and JPEGs. Here’s the procedure I used to determine whether or not there was a difference between the original and the copy:

  1. Create a new RGB 8-bit file in Photoshop with the Adobe RGB (1998) color space.
  2. Create a rainbow gradient
  3. File -> Save for Web as PNG-24
  4. File -> Place Embedded the PNG file just saved back into the original file
  5. Change the PNG layer blend mode to Difference

If there was no difference between the original file and the PNG layer, the appearance should be solid black. What I found was that it wasn’t. There were very noticeable areas that were non-black which meant that the PNG file wasn’t the same as the original. This perplexed me because if PNG compression is truly lossless, then the two images should be identical.

This image shows the result of importing a PNG-24 format file in the sRGB color space on top of the test image above and changing the layer blending mode to Difference. The fact that the image is not solid black shows that there are differences between the original and the PNG file.

This image shows the result of importing a PNG-24 format file in the sRGB color space on top of the test image above and changing the layer blending mode to Difference. The fact that the image is not solid black shows that there are differences between the original and the PNG file.

[REWIND: HOW TO CREATE A WEB-SIZED IMAGE EXPORT PRESET IN LIGHTROOM]

Color Shift

Further testing showed that the problem was not in the PNG compression. Instead, the problem was that there was a color space shift. The original image was in the Adobe RGB color space, but the PNG file was saved as sRGB—even though I hadn’t clicked the Convert to sRGB checkbox on the Save for Web dialog. But Photoshop did the conversion anyway (more on this below). Since some of the colors in the original rainbow couldn’t be contained in the sRGB color space, there was a color shift.

In some cases, Photoshop will convert to sRGB even if you don’t click the Convert to sRGB checkbox. Also, embedding a color profile will help get the best color.

In some cases, Photoshop will convert to sRGB even if you don’t click the Convert to sRGB checkbox. Also, embedding a color profile will help get the best color.

There’s a solution/workaround, but the correct approach depends on your needs. The first question is whether you plan to post your photo on the web or not. If so, you may be best off accepting the sRGB conversion because that’s the web standard color space. If not, you may still want to use the PNG file format in order to take advantage of the lossless file compression. A compressed PNG file can be a fraction of the size of a PSD, TIF or raw file. This can save upload/download time when emailing or otherwise sharing files online.

Saving for the Web

The latest versions of some of the major web browsers are capable of recognizing an embedded color profile and displaying the image correctly. This means it’s possible to embed a color profile like the Adobe RGB profile in a PNG file to be displayed on the web and not experience the color shift you’d see with sRGB. However, support for embedded profiles depends on the specific browser and platform (PC, Mac, mobile device).

If you’re sharing files with other photographers or pros who are using a color-managed workflow, it’s well worthwhile to embed a color profile such as Adobe RGB or Pro Photo.

Test image exported as PNG-24 with an embedded Adobe RGB (1998) color profile

Test image exported as PNG-24 with an embedded Adobe RGB (1998) color profile

Test image exported as PNG-24, converted to sRGB with an embedded sRGB color profile. The differences are most obvious in the reds and purples. Note: the differences are visible on Windows PCs using the latest versions of the Chrome and Firefox browsers. Differences may not be visible on other platforms or other browsers.

Test image exported as PNG-24, converted to sRGB with an embedded sRGB color profile. The differences are most obvious in the reds and purples. Note: the differences are visible on Windows PCs using the latest versions of the Chrome and Firefox browsers. Differences may not be visible on other platforms or other browsers.

Color Settings in Photoshop

Earlier, I mentioned that Photoshop converted my PNG to sRGB even though I hadn’t checked the Convert to sRGB checkbox on the Save for Web dialog. A little more sleuthing uncovered the reason. I checked my color settings (Edit ->  Color Settings) and it showed that I had sRGB as my Working Space. I subsequently changed my RGB Working Space to Adobe RGB (1998). Having sRGB as the default setting won’t cause a problem when opening photos containing an embedded Adobe RGB or Pro Photo profile, but it will affect what happens when you save a PNG or JPEG without checking the Convert to sRGB option.

JPEG for the Web

I also tested saving JPEGs using the Save for Web Maximum quality preset. I found that for my sample files there was no loss of quality when using Maximum as long as I avoided color shifts. You’ll generally get better compression with JPEG than with PNG, but if quality is your priority you may want to stick with PNG since it’s guaranteed to be lossless.

Conclusion

Using Difference blending mode can be a useful technique for comparing any two layers to see where differences exist. If you use the PNG-24 format and avoid color shifts, you can be sure of getting the maximum image quality in a compressed file format.

Advertisement

About

Dave Salahi is a photographer, Photoshop artist and Photoshop instructor in Southern California. In a previous life Dave was a software developer and still does some website development work. His website, The Photo Performance, features Photoshop tutorials and other photography info.

9 Comments

  1. Kurk Rouse

    Facebook really destroys your image quality, this is still a topic that I find my self coming back to time and time again. I will give PNG a chance and hope for the best . Thanks for the post.

    5
  2. Herm Tjioe

    So even these niggling default settings are the willful upload troublemakers. What if setting default on sRGB all the way through and save in PNG, will that alter fidelity ?

    4
    • David Salahi

      Herm, if you use the sRGB color space throughout your workflow and then save as PNG-24 you won’t lose any quality. But be sure to use PNG-24 (not PNG-8). And you should also be aware that sRGB is a small color space which means it may not be able to represent all the colors in a photo. If you shoot in sRGB you’re losing color quality from the very beginning. The Adobe RGB (1998) and Pro Photo color spaces contain many more colors than sRGB so they are preferred whenever possible. Even if you’re shooting only for the web as a final destination you’ll be better off shooting in Adobe or Pro Photo and then converting to sRGB only as your final export step.

      3
    • Herm Tjioe

      Thanks, David. I do shoot in Adobe RGB and have preferred the most fidelity. It’s the saved files into my workspace for processing that I hadn’t thought much of before. I appreciate your explanation and helpful guide

      2
  3. Petr Kulda

    Thanks fo good article

    3
  4. Stan Rogers

    There is a point at which this can get a little bit silly. You have no real way of knowing whether your viewers will be using software/devices that can handle anything other than the sRGB colour space, and an image displayed with the wrong colour space suffers a heck of a lot more damage than an image that is converted (with care and the right choice between “Perceptual” and “Relative colorimetric” gamut conversion for that image) to a target colour space that enjoys essentially universal support (with the caveat that low-bit monitors can only even approximate that). It would be really cool if we could query colour space support the same way we can query device size/resolution, then serve the appropriate image for the request, but we can’t. So it becomes a matter of deciding whether your viewership is general (you want everyone to be able to see it with reasonable fidelity) or targeted (there is a smaller number of viewers you care about, and they’re likely to have more capable or up-to-date hardware and software — but keep in mind that if you’re showing to reps/buyers, *they’re* going to care about what the image looks like in sRGB, since that will be their target space 99.9% of the time).

    In any case, there isn’t much loss with a high(est)-quality JPEG — you really do have to diff to see anything — and the difference in file size compared to PNG is significant. You can get further file size savings by running that JPEG through something like JPEGmini. (JPEGmini optimizes the compression using some deep voodoo that fails to introduce any of the expected artifacting, such that a file saved using “12″ is Ps (or “100″ in Lr/Gimp/etc.) winds up about the same size as a “7″ or “8″, depending on the image, without *apparently* changing quality at all. No, I don’t understand how, and that annoys me. But there’s a “forever free” trial with a 20-images-per-day cap if you want to try it out. The uncapped version is $20 if it works for you. No affiliation, just a satisfied customer.)

    7
    • David Salahi

      Hi Stan, you’re right, there isn’t much loss with the highest quality JPEG setting. And PNG-24 can yield significantly larger file sizes than JPEG. This article is primarily about the case where you want to maximize image quality and when file size considerations are a distant second. Even though PNGs can be large compared with JPEGs they are typically small when compared with TIFFs or PSDs. And saving as a PNG-24 is a guarantee of no quality loss as long as you avoid color space conversions.

      An example of a great use of PNG is a website where I sell some of my prints. They only accept PNGs from photographers when we upload. That guarantees that our printed images will be of the highest possible quality while also minimizing file size and avoiding any potential file compatibility issues.

      Yes, obsessing about image quality could become silly. You’re quite right that, as image creators, we have no control over the hardware, software or physical environment in which our photos will be seen. Light coming in a window or a badly adjusted monitor can be far more detrimental to an image than a color space conversion. And even if we provide a handmade print on the best paper with the best quality ink we still have no control over the viewing environment.

      Still, as a visual artist, I care about the quality of the images I offer. If I can get better image quality by simply ticking one box instead of another I’ll do that. And I’ll be glad knowing that others who care about image quality will appreciate the difference.

      Thanks for the tip about JPEGmini! I’m going to try it out.

      2
  5. Steven Lelham

    Good read

    2

Leave a reply

Advertisement