tag (see page 352). To set your graphic apart from the text on the page, press Enter (Return) first to create a blank line to give the image its own paragraph. 3. Choose Insert➝Image. Alternatively, from the Insert panel’s Common category, you can click the Image button (see Figure 6-2). Or, if you’re a keyboard shortcut fan, press Ctrl+Alt+I (-Option-I). In any case, the Select Image Source dialog box opens. This box is nearly identical to the Select File window that appears when you add a link to a page (see Figure 5-4). 4. Browse to and then select the graphics file you want to add to the page. The file must be in one of the formats that work on the Web: GIF, JPEG, or PNG. Store the file somewhere in your local site folder (see page 44) or in one of its sub-folders. If you don’t, Dreamweaver can’t add the correct path to your web page. Note: The primary file format for Fireworks, Adobe’s web-friendly image-editing program, is PNG (just as Photoshop’s format is PSD). However, a native Fireworks file contains additional data the program uses to keep track of fonts, layers, and other information. That extra data significantly increases the file size. So always make sure you use the Export command in Fireworks to properly compress the image into a GIF, JPEG, or PNG file without all the extra Fireworks info.
222
dreamweaver cs5.5: the missing manual
Adding Images
Figure 6-2: The Image menu on the Insert panel’s Common category provides tools that let you add graphics to your pages. If you’re using Dreamweaver’s “Classic” workspace (top) the Insert panel is actually in the toolbar near the top of your screen. The “Designer” workspace layout (bottom) displays the Insert panel grouped with other panels on the right edge of the screen. See page 33 for more on Dreamweaver workspaces.
That’s why, if you select a graphic for insertion that’s not already in your site folder, Dreamweaver offers to add a copy of it there. If you choose Yes, then a Copy File As dialog box opens so you can save the file in your local root folder, renaming it if you wish. If you choose No, then Dreamweaver uses a file-relative path (beginning with file:///) for the image’s src property. But clicking No is a bad idea: While you can see the graphic as you work in Dreamweaver on your computer, the graphic doesn’t appear once you move the document to the Web (see the box on page 176). Note: Dreamweaver lets you choose a Photoshop (PSD) file from the Select Image dialog box when you insert an image, but it doesn’t actually insert the PSD file. It opens a second window where you can save the image as a GIF, JPEG, or PNG file with web-appropriate optimization settings. Page 226 has the full story on this feature.
5. Click OK (Windows) or Choose (Mac). You should see an Image Tag Accessibility Attributes window, which lets you assign an “alternate” text description of the image (for the benefit of those who can’t see your images—those using screen-reading software, for instance). If you don’t see this window, somewhere along the line, you or someone else turned off this
chapter 6: images
223
Adding Images
option—you can turn it back on by going to Edit➝Preferences➝Accessibility (Dreamweaver➝Preferences➝Accessibility) and turning on the checkbox for Images; see page 237. 6. Type a short text description of the image, and then press OK. Dreamweaver inserts the image. The options in the Image Tag Accessibility Attributes window are described in greater detail on page 234 and in the box on page 237, but in a nutshell, you should add a brief description for any image that adds meaning to a page. For example, if you insert a graphic of your company’s logo, the alternative text should be your company’s name. For complex images, you can use the Accessibility Attributes window’s second option—Long Description—to link to another page with detailed information about an information-heavy graphic, such as a chart or map. You’ll almost always skip it, but for more details on how it works, see the box on page 237. Tip: Dreamweaver also permits several drag-and-drop techniques so you can quickly add images to your pages. Make sure you set up a site as described on page 39. Then open the Files window (press F8). You can drag any graphics file from that window right into an open Dreamweaver document. You can also drag graphics in from the Assets panel, as described on page 40. Dreamweaver even lets you drag a graphic from your desktop onto a web page. If you do this, Dreamweaver dutifully informs you that you must copy the file into your site folder (and provides a dialog box that lets you specify which folder), so that the image shows up when you transfer your site files to the Web. (You can even define a default Images folder for a site, so that when you drag an image onto a page, Dreamweaver automatically copies it into the correct folder.) Dreamweaver even lets you drag Photoshop files into a Dreamweaver document.
Adding an Image Placeholder You’ll often find yourself working on a website without all the pieces of the puzzle; you may start building a page even before your client gives you all the necessary text, for example. Or you may find that a photograph hasn’t been shot, but you want to get the page ready for it. Other times, you may be responsible for building web pages while another designer creates banners and navigation buttons. To help out in these situations, Dreamweaver includes the Image Placeholder button. It lets you insert a placeholder—called an FPO (For Placement Only) image in publishing lingo—so you can stake out the space on a page for a graphic that isn’t ready yet. This way, you can lay out the structure of a page without waiting for all its graphics. To insert a placeholder, do one of the following: • Choose Insert➝Image Placeholder. • In the Insert bar’s Common category, select the Image Placeholder icon from the Image menu (see Figure 6-2). 224
dreamweaver cs5.5: the missing manual
Adding Images
In the window that appears (see Figure 6-3), type a width and height for the image, which determines how much space the placeholder reserves on the page. This should match the dimensions of the final image. The Name and “Alternate text” fields are optional. (If you fill them out, they appear in the Name and Alt boxes of the image’s Property inspector, as discussed next.) Figure 6-3: The values you type for Name, Width, Height, and “Alternate text” appear in the Property inspector after you insert an image placeholder. The Color option lets you choose a color for the placeholder, but avoid it or you’ll add unnecessary code to your page, which Dreamweaver doesn’t remove once you add the real graphic).
The Color box lets you specify a color for the placeholder—presumably to make the placeholder more colorful than the default gray color. Avoid this option: It inserts inline CSS code that Dreamweaver doesn’t remove when you replace the placeholder with a real graphic, adding unnecessary code to the page. Worse, if the image you eventually use has any transparent areas, the color defined here shows through the graphic! Warning: Dreamweaver takes the name you give a placeholder and uses it as an ID attribute to the
![]()
tag. Both JavaScript and CSS use IDs. If the name you provide for the image placeholder is the same as an ID name for a CSS style you created, you can run into some weird display problems. Bottom line: Unless you plan on using a CSS ID style to format the image or JavaScript to control the image, just leave the Name field empty when you insert the placeholder.
Of course, using a placeholder doesn’t do you any good if you don’t eventually replace it with a real image. Once you’ve got the actual image, double-click the placeholder. The Select Image Source window appears. Follow steps 4 through 5 on pages 222 and 223 to insert the new image. If you also own Fireworks, Adobe’s web graphics companion program, the image placeholder gives you an added benefit. When you select an image placeholder in the document window, the Property inspector includes a button called Create. Click this button to launch Fireworks and open a new, blank graphics document set to the exact dimensions you specified earlier. You can then create your graphic in Fireworks. After you save the file, Fireworks exports it to whatever folder you specify, and then automatically inserts it into your document, replacing the placeholder image.
chapter 6: images
225
Inserting an Image from Photoshop
Inserting an Image from Photoshop Since Adobe makes the world’s most popular image-editing program, Photoshop, it only makes sense that the Dreamweaver engineers provide a streamlined process for moving images back and forth between Photoshop and Dreamweaver. You can add a Photoshop document to a web page two ways: Insert a PSD file (Photoshop’s native format), or copy an image from Photoshop, and then paste it into a Dreamweaver document. The first method—inserting a PSD file—supports what Adobe calls Smart Objects, which lets Dreamweaver keep track of whether you update the original Photoshop file, and, if so, gives you the option to update the compressed, web-ready version of the image. Nice. That’s great news if you’re the type who’s constantly tweaking your artwork in Photoshop. The second method—copying and pasting from Photoshop— doesn’t keep track of any changes to the original Photoshop file. Both methods are explained in the following pages.
Method 1: Using the Insert Image Object You can insert a regular Photoshop file using the same steps described on page 222 for inserting GIF, JPEG, or PNG files. For example, use the Image button on the Insert panel, or choose Insert➝Image. The Select Image Source window appears, just as it does when you insert a standard web-ready file. You can then choose a Photoshop document (a .psd file), and click the OK (Choose on Mac) button. Instead of just inserting the image, however, Dreamweaver opens an Image Preview window that lets you choose how to optimize the graphic (see Figure 6-4). Note: You can also insert a PSD file by dragging it directly from the desktop (or any folder) and dropping it into a Dreamweaver document. If you stored the PSD file somewhere inside your local root folder, you can drag it from the Files panel and drop it onto the page.
Although Dreamweaver gives you lots of options, the decision-making process can be boiled down to three steps: 1. From the Format menu (circled in Figure 6-4), choose the graphic format you want to use on your page. You get to choose from three web-friendly formats: GIF, JPEG, and PNG (see the box page 228). In general, you’ll want to choose PNG8 for images with solid colors and text, like logos; use JPEG for photos. And if you really want to have 256 levels of transparency (great for drop shadow effects, but—as noted on page 228—not so great for Internet Explorer 6), then choose PNG32. Note: You can’t import animated GIF images using the Image Preview window; instead, you need to first export the animated GIF from the program in which you created it (like Fireworks or Photoshop), and then import it into Dreamweaver.
226
dreamweaver cs5.5: the missing manual
Inserting an Image from Photoshop
Set target Zoom in/out Compare optimization file size settings Crop image Preview optimization settings
Figure 6-4: Picking the proper optimization for an image is usually a matter of trial and error, so you’ll often want to see how an image looks and compresses as a JPEG and a PNG file before you decide which format to choose. You can compare different file types and optimization settings side by side by clicking either the “2-up” or “4-up” buttons at the bottom of the Image Preview window (circled). 2-up lets you compare two optimization settings (pictured here), while 4-up shows four previews. This is a great way to see which file format gives you the bestlooking image at the smallest file size.
2. Set your image’s optimization settings. The exact optimization choices you have depend on the graphic format you selected in step 1 (see discussion below). Make your choices using the menus and buttons on the window’s left-hand side. In the right half of the Image Preview dialog box, Dreamweaver shows you what the final, optimized graphic will look like; you can even compare different optimization settings (see Figure 6-4). The preview window also displays information about the final optimized graphic, such as its file type, the quality or kind of compression it uses, the number of colors it supports, the final size of the file, and how long the file will take to download over a 56K dial-up modem. Figure 6-4 shows what the image looks like when you save it as a JPEG (top preview image) and as a PNG8 file (bottom preview image). The JPEG version has a quality of 60 (see “JPEG optimization options” on page 230 for a discussion of this property), supports millions of colors, and is 18.79 kilobytes (K) in size. The PNG24 version, on the other hand, is 529.79 K! Given the comparable image quality, JPEG is the obvious choice. chapter 6: images
227
Inserting an Image from Photoshop Up To Speed
GIFs, JPEGs, and PNGs: The Graphics of the Web Computer graphics come in hundreds of file formats. The assorted acronyms can be mind-numbing: JPEG, GIF, TIFF, PICT, BMP, EPS, SVG, and so on. Fortunately, the limited graphics formats the Web uses makes things simpler. All of today’s web browsers support three common graphics formats, each of which provides good compression; through clever computer manipulation, compression reduces a graphic’s file size so it can travel more rapidly across the Internet. The format you choose depends on the image you wish to add to your page. GIF (Graphics Interchange Format) files provide good compression for images with big areas of solid color: logos, text, simple banners, and so on. GIFs also offer singlecolor transparency, meaning you can make one color in the graphic disappear, permitting the background of a web page to show through part of the image. In addition, you can create limited animations with GIF files (like a flashing “Buy Me” button). (If you don’t need to animate an image, the PNG8 format discussed below is a better choice than GIF.) GIF images support a maximum of only 256 shades of color, generally making photos look posterized (in other words, not completely realistic). That radiant sunset photo you took with your digital camera won’t look so good as a GIF file. JPEG (Joint Photographic Experts Group) graphics, on the other hand, pick up where GIFs leave off. JPEGs support millions of colors, making them ideal for photos. Not only do JPEGs do a better job on photos, they compress multicolored images much better than GIFs, because the JPEG compression formula considers how the human eye perceives adjacent color values; when your graphics software saves a JPEG file, it runs a complex color analysis to lower the amount of data required to accurately represent the image. On the downside, JPEG compression makes any text you have in an image and large areas of solid color
228
look blotchy, so it’s not a good choice for logos or simple drawings. Finally, the PNG (Portable Network Graphics) format includes the best features of GIFs and JPEGs, but you need to know which version of PNG to use for which situation. PNG8 is basically a replacement for GIFs. Like a GIF, it supports 256 colors and basic one-color transparency. However, PNG8 usually compresses images to a slightly smaller file size than GIF, so PNG8 images download a tiny bit faster than the same image saved in the GIF format. PNG24 and PNG32 offer the expanded color palette of JPEG images, without any loss of quality. This means that photos saved as PNG24 or PNG32 tend to be of higher quality than JPEGs. But before you jump on the PNG bandwagon, JPEG images offer very good quality and a much smaller file size than either PNG24 or PNG32. In general, JPEG is a better choice for photos and other images that include lots of colors. Finally, PNG32 offers one more feature that no other format does: 256 levels of transparency (also called alpha transparency), which means you can actually see the background of a web page through a drop shadow on a graphic, or even create a graphic with 50 percent opacity (meaning you can see through it) to create a ghostly translucent effect on a page. Unfortunately, Internet Explorer 6 for Windows doesn’t support PNG32’s 256 levels of transparency—instead of seeing through the transparent areas, IE6 replaces the transparent areas with a hideous blue background. (Several JavaScript-based techniques—see http:// tinyurl.com/57acq6, for example—help IE 6 display PNG transparency correctly.) Fortunately, Internet Explorer 7, 8, and 9 do support PNG transparency, as do Firefox, Safari, Chrome, and Opera, and since IE6 is rapidly approaching extinction, you might simply ignore that browser’s problem with PNG transparency.
dreamweaver cs5.5: the missing manual
Inserting an Image from Photoshop
3. Click OK, and then name and save the file on your site. Dreamweaver saves the new image file and places it into your page—at this point it’s a GIF, JPEG, or PNG file. Dreamweaver adds a small icon in the upperleft corner of the image to indicate that the image is a Smart Object and retains a link to the original PSD file. What makes it “smart” is that Dreamweaver tracks any changes to the PSD file—if you decide to open Photoshop and add some cool effect to the image, Dreamweaver knows you changed the original. At this point, you can update the image on your web page directly in Dreamweaver. Page 251 shows you how. When you insert a Photoshop image this way, Dreamweaver, unfortunately, ignores images you made using Photoshop’s “slice” tool. This handy tool lets web designers export just bits and pieces of a complete web page design in Photoshop—for example, you could design the look of a site’s home page in Photoshop, show it to your client for feedback, then export just parts of the design as separate images files, like a logo in the upper-left corner of the document, individual navigation icons along the top, or a photo in the middle of the document. So if you want to use an exported slice as a graphic on your web page, the importfrom-Photoshop technique isn’t the best; Dreamweaver tries to insert the entire image, not the slices. However, there’s a workaround: As pictured in Figure 6-4, you can use the Image Preview box’s crop tool to extract just one rectangular area from the image; Dreamweaver optimizes and imports only that part of the file. Best of all, Dreamweaver remembers the crop you set, so you can update the entire image in Photoshop, but your page retains just the updated cropped portion. Tip: For ultra-precise cropping control, click the Image Preview box’s File button (Figure 6-5 top left); check the “Export area” box; and then enter precise pixel values for the crop—where it should start, and how wide and tall it should be.
Cropping an image this way has no effect on the original PSD file—it remains full size. You can even use different parts of the same image (have multiple Smart Objects, in other words). Just follow the Insert➝Image routine each time. When you update the original Photoshop file, you can update every Smart Object based on that image.
chapter 6: images
229
Inserting an Image from Photoshop
Figure 6-5: In the Image Preview window, the options under the File tab let you precisely control the scale of your final image. For example, if your original Photoshop image is very large, you could type 25 in the Scale section’s “%” field, to make the final, imported image 25 percent the size of the Photoshop image. This setting has no effect on the Photoshop document itself, just on the final image. You can also import just a selected area of the image by turning on the “Export area” checkbox and then specifying the part of the image you want to export to your site. You can export different areas of the same image. Doing so lets you draft your web page in Photoshop and insert separate bits of it, such as individual icons and a banner.
JPEG optimization options Dreamweaver doesn’t give you many choices for optimizing JPEG images. Basically, you select a quality level that affects both how good the image looks and its file size. The higher the quality, the larger the file; the worse the quality, the smaller the file. Dreamweaver’s Quality setting runs from 1 (low quality/small file) to 100 (high quality/large file). Eighty is a good choice for very good quality and