Dive into this comprehensive Photoshop for Web Design tutorial covering topics such as transparent photos, 8-bit graphic formats, optimizing colors, and exporting 1x & 2x graphics, along with an exercise on optimizing graphics as PNG or GIF.
This exercise is excerpted from Noble Desktop’s past web design training materials and is compatible with Photoshop updates through 2020. We now teach Figma as the primary tool for web and UX & UI design. To learn current skills in web design, check out our Figma Bootcamp and graphic design classes in NYC and live online.
Topics covered in this Photoshop for Web Design tutorial:
Transparent photos, 8-bit graphic formats: GIF versus PNG-8, PNG transparency, Properly optimizing colors: limited colors versus gradients, Exporting 1x & 2x graphics
Exercise Preview
Exercise Overview
In this exercise you’ll learn how (and when) to optimize graphics as PNG or GIF.
Transparent Photos
JPEG does not support transparency, so how do we optimize a photo with a transparent background? Let’s see.
- In Photoshop, close any files you have open.
- Go to File > Open or hit Cmd–O (Mac) or Ctrl–O (Windows).
- Navigate to Desktop > Class Files > yourname-Photoshop for Web Class > Graphics to Optimize and double–click iphone-hand-mockup.psd.
- In the Layers panel, hide the bg color layer by clicking the eye
.
- We don’t need the excess transparent pixels, so choose Image > Trim.
- Set Based On to Transparent Pixels.
- Make sure Trim Away has all sides checked on.
- Click OK and Photoshop quickly and precisely trims the image for you!
- Choose File > Export > Save for Web (Legacy).
- On the right of the window, under Image Size, set W (width) to 400 px and hit Tab to apply it.
-
At the top right of the window, go into the Preset menu and choose PNG-24.
Unlike JPEG compression, PNG uses a lossless compression. That means it does not lose quality, so you don’t get ugly JPEG artifacting.
- Hit Cmd–Plus(+) (Mac) or Ctrl–Plus(+) (Windows) a few times to zoom in so you can see the details closely.
- Notice the background has a checkerboard pattern indicating it’s transparent, and the edge of the hand blends into that transparent background.
-
Let’s try another file type. At the top right of the window, go into the Preset menu and choose PNG-8 128 Dithered.
PNG-24 has millions of colors (24 bits), whereas PNG-8 has up to 256 colors (8 bits).
- On the right, set Colors to 256.
-
Look closely at the following:
- The colors in the hand, burger, etc. are not not as smooth as we’d like. This preset has some Diffusion dithering (which scatters pixels to help smooth things out) but you can still see some flat bands of colors.
- The edge of the hand now has a sharp white halo instead of blending smoothly into the transparent background. While both PNG-8 and PNG-24 support partial transparency, Save for Web only supports partial transparency in PNG-24. Save for Web is not capable of making a partially transparent PNG-8.
- Click Cancel.
- Choose File > Export > Export As.
- At the top right, set Format to PNG.
- Make sure Transparency is checked on.
- Make sure Smaller File (8-bit) is unchecked.
- Under Image Size, set Width to 400 and hit the Tab key to apply the change.
- At the bottom of the window, click the Plus (+) button a few times (until you can see the edge of the hand pretty well).
- On the left side, below iphone-hand-mockup notice the file size is around 206 KB.
- On the right, check on Smaller File (8-bit).
- On the left, notice the file size is around 52 KB. Wow, that’s a lot smaller!
- Notice the transparency still looks fine. Unlike Save for Web, Export As knows how to create a partially transparent PNG-8.
- Also notice that the color gradations look better than Save for Web. There is some banding because PNG-8 only has 256 colors, but the color reduction of Export As is much better than Save for Web.
-
At the bottom of the window, click on the zoom percentage (between the – and + buttons) to jump back to 100% zoom.
You can’t see the color banding at this size, so we can save a lot of file size by using PNG-8 instead of PNG-24 for this image!
- This 400px wide image is what we need for 1x, but we also need a 2x version. At the top left of the window, click the Plus (+) button to the right of Suffix.
-
Set the second size to 2x so you end up with the following:
- Click Export.
- Navigate to Desktop > Class Files > yourname-Photoshop for Web Class > Graphics to Optimize > optimized.
- Click Open (Mac) or Select Folder (Windows).
Save the Photoshop file and close it.
8-Bit Graphic Formats: GIF versus PNG-8
SVG files work great in webpages, but they’re not well supported in HTML email or mobile/tablet apps. PNG and GIF are well suited to optimizing graphics and work well in emails. PNGs are commonly used in mobile/tablet apps. Let’s see how to export PNG and GIF.
- Go to File > Open or hit Cmd–O (Mac) or Ctrl–O (Windows).
- Navigate to Desktop > Class Files > yourname-Photoshop for Web Class > Graphics to Optimize and double–click nyc-logo@2x.psd.
- Let’s crop off the extra transparent pixels. Go to Image > Trim.
- Set Based On to Transparent Pixels.
- Make sure Trim Away has all sides checked on.
-
Click OK.
For our design, we need partial transparency. This graphic doesn’t have many colors, so PNG-8 might work well. As we just learned, the PNG-8 in Save for Web does not support partial transparency, but Export As does.
- Go to File > Export > Export As.
- Make the window as large as possible.
- At the bottom of the window, click the Plus (+) button until the preview fills the entire window.
-
Before we try PNG, let’s try GIF. At the top right of the window, set Format to GIF.
Unlike JPEG, GIF and PNG both use a lossless compression. While you won’t get ugly JPEG artifacting, the limited color palette of GIF or PNG-8 may in some cases degrade the appearance of images with many colors.
-
In the empty parts of the logo, you should notice a checkered pattern that indicates transparency. Look closely at the edges, noticing that some pixels are light orange or white. (Zoom in more if needed).
We need partial transparency, which means that some of the checkerboard pattern should be peeking through, as shown in the image below:
GIF transparency is all or nothing. Any partially transparent pixels become completely opaque, as shown above. This would create an ugly light halo effect when placed over a darker background. This is not usable. Sometimes GIF can be smaller than PNG for simple graphics with no transparency, but typically PNG is smaller and has a usable transparency.
- If you can’t see the entire graphic, click the Minus (–) button at the bottom of the window until you can.
- Change the Format to PNG.
-
To compare the file sizes, check and uncheck Smaller File (8-bit) a few times, while watching the file size on the left of the window.
The visual quality is the same, but the PNG-8 is around 1.1K and the PNG-24 is a little bigger at 1.4K. Both support partial transparency, so we should use the PNG-8.
- Make sure that Smaller File (8-bit) is checked on before proceeding.
-
Click Export.
NOTE: For this graphic we’re only going to export a hi-res (@2x) version. As more displays become hi-res, sometimes we only use a 2x graphic and don’t bother making a 1x version (especially for small files like this).
- Navigate into Desktop > Class Files > yourname-Photoshop for Web Class > Graphics to Optimize > optimized. Keep the suggested filename nyc-logo@2x.png and click Save.
Save the Photoshop file and close it.
Optimizing a Graphic with a Gradient
The last graphic had flat colors, but what about graphics with more colors and gradations? Let’s see how to optimize them.
- Go to File > Open or hit Cmd–O (Mac) or Ctrl–O (Windows).
- If you’re not still in the Graphics to Optimize folder, navigate to Desktop > Class Files > yourname-Photoshop for Web Class > Graphics to Optimize.
-
Double–click app-store-icon@2x.psd.
We do not need partial transparency for this graphic because we want to display it on a white background. That gives us more options to reduce the file size while maintaining quality in the blue gradient.
- Go to File > Export > Save for Web (Legacy).
- In the Optimized tab, hit Cmd–0 (Mac) or Ctrl–0 (Windows) to make the preview fill the entire window.
-
PNG-24 files are typically larger than the other options, but let’s get a sense of the maximum size and quality for this file. At the top right of the window, go into the Preset menu and choose PNG-24.
Yikes, this small icon is almost 24K (you can see it at the bottom left of the window).
- Supporting transparency generally adds a bit of file size to a PNG-24, so uncheck Transparency. The file is a bit smaller, but it’s still unacceptably large for such a small icon. Let’s try some other options.
-
While JPEGs are generally better for photos than graphic art like this icon, JPEG might be more ideal because our image has a lot of colors and gradations. Set the Preset to JPEG High.
At around 12.31K, the file size is smaller than the PNG-24. The default 60 Quality produces quite a bit of artifacts around the edges, but at normal size you probably wouldn’t notice it. Can we do even better though?
-
From the Preset menu choose GIF 128 Dithered.
Dithering scatters pixels to help make gradual blends look smoother. It improves the appearance, but it increases file size. Even with dithering, the gradient has a little banding (colors forming stripes), but it would barely be visible at a normal size.
- At the bottom left of the window, notice that the file size is about 8.576KB.
- From the Preset menu choose PNG-8 128 Dithered.
- The image looks the same, but at the bottom left of the window notice that the file size is smaller (about 6.673KB).
- Uncheck Transparency and notice the file size shrinks a little more.
-
Let’s see if we can get away with using fewer colors. Set Colors to 64.
NOTE: The newer Export As does not let us reduce the number of colors, which is why we’re using Save for Web.
-
This does create more noticeable color bands, but let’s experiment with some other settings that may help. There are different ways for Photoshop to decide which colors are being used.
From the menu that reads Selective, test out the Perceptual and Adaptive color reduction algorithms, while keeping an eye on the image quality and file size.
-
Visually there isn’t much difference between the three choices, but Selective is the smallest, so switch back to Selective.
NOTE: Perceptual, Selective, and Adaptive base their color choices on the actual image. The other options are preset color palettes and are typically not desirable.
- Set Dither to 100%
- Let’s experiment with the type of dither to see how that works. From the menu that reads Diffusion, switch to Pattern and then Noise.
- Pattern and Noise look a bit smoother than Diffusion, but they increase the file size. Switch the dithering back to Diffusion.
-
Hit Cmd–1 (Mac) or Ctrl–1 (Windows) to view at 100% so you can judge the quality at a more appropriate size.
At this size Diffusion looks good, and it’s a smaller file size.
-
Let’s see if we can reduce the colors even more. Set Colors to 32.
You may be able to see a slight increase in the color banding (stripes), but it’s quite subtle. This is usable, although the file size isn’t that much smaller.
- We prefer the slightly smoother gradient, so set Colors back to 64.
-
Let’s compare the file sizes, from biggest to smallest. (Don’t worry if your sizes are slightly different than ours.)
PNG-24: “Export As”, No Transparency 22.7K PNG-24: “Save for Web”, No Transparency 21.8K JPEG: “Export As”, 60% quality 12.4K JPEG: “Save for Web”, 60% quality 12.31K PNG-8: “Export As” 10K PNG-8: 256 colors, 88% Diffusion Dithering 9.893K PNG-8: 64 colors, 100% Diffusion Dithering 5.451K Photoshop’s Export As feature does not let you reduce the number of colors. So if you don’t need transparency (and the file looks good with less than 256 colors), use Save for Web to further reduce file size.
NOTE: Because Save for Web and Export As use different algorithms, their output can have different file sizes and look different.
- At the bottom right, click Save.
- Navigate into Desktop > Class Files > yourname-Photoshop for Web Class > Graphics to Optimize > optimized. Because it is a HiDPI/Retina image, keep the filename app-store-icon@2x.png
- Save the Photoshop file and close it.
If you want to see the files that you exported, they are in Desktop > Class Files > yourname-Photoshop for Web Class > Graphics to Optimize > optimized.
App Store Graphics
Apple’s iOS App Store: If you want to use an App Store badge on your website, you should read Apple’s guidelines at tinyurl.com/ap-brand
Google Play for Android: If you want to use a Google Play badge on your website, you should read Google’s guidelines at tinyurl.com/gogl-brand