{"id":166,"date":"2008-07-07T22:30:31","date_gmt":"2008-07-08T03:30:31","guid":{"rendered":"http:\/\/cssnewbie.com\/?p=166"},"modified":"2008-07-07T22:30:31","modified_gmt":"2008-07-08T03:30:31","slug":"print-friendly-images","status":"publish","type":"post","link":"https:\/\/cssdeck.com\/blog\/print-friendly-images\/","title":{"rendered":"Print-Friendly Images and Logos with CSS"},"content":{"rendered":"<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/07\/printfriendly-400.gif\" alt=\"\" title=\"printfriendly-400\" width=\"400\" height=\"216\" class=\"alignnone size-full wp-image-170\" \/><\/p>\n<p>In certain instances, not everyone views every portion of your website online: eventually, someone is going to print parts of it. In many cases, this is perfectly fine: if you have a <a href=\"http:\/\/cssnewbie.com\/7-tips-print-style-sheets\/\" title=\"7 Tips for Great Print Style Sheets\">print style sheet that takes care of your worst sins,<\/a> your website should look okay. But one area where it may still look lackluster is the images.<\/p>\n<p>It\u2019s a simple problem of resolution. Images are always displayed on the web at 72dpi (dots per inch). However, nearly all printers can handle resolutions far higher than this. What that means is the text of your printed web page will be printed at a high resolution \u2013 likely at least 300dpi. Your images, however, won\u2019t have enough information to print out at 300dpi or higher. Instead, because the browser and printer know how much <em>space<\/em> (vertically and horizontally) the image is supposed to take up, they\u2019ll up-sample the image, doubling and tripling the number of pixels in the image via crude pixel duplication algorithms until the image is the correct size. The result is a fuzzy image with jagged edges.<\/p>\n<p>Back in 2005, <a href=\"http:\/\/www.alistapart.com\/articles\/hiresprinting\">an article by Ross Howard appeared on A List Apart<\/a> describing a way around this problem. It solves a real problem with a viable solution, but the author doesn\u2019t give a lot of practical information on how to implant the solution. So here\u2019s my take on that technique.<\/p>\n<p>The trick is this: send a low-resolution version of your image to the screen, and a high-resolution version to the printer. It\u2019s a fairly simple trick, but it does have a few problems. For one, it requires a bit of extra XHTML to pull it off. For another, the end user has to download <em>both<\/em> version of the image when they view the page, and the high-res image is bound to use up significantly more bandwidth. As such, I would recommend only using this technique for smaller images, and when a crisp, clean image is vitally important. A company logo would be an excellent example of this.<\/p>\n<p>So here\u2019s how it\u2019s done. First off, we\u2019ll have to make our logo. I built an example up quick in Photoshop:<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/07\/printfriendly1.gif\" alt=\"\"  width=\"400\" height=\"234\" class=\"alignnone size-full wp-image-167\" \/><\/p>\n<p>Before you actually start building the logo, it\u2019d be a good idea to know what size you want your large and small versions to be. I decided that I wanted my screen-size logo to be 150 pixels wide by 75 tall. However, I built my high-res version to be 600&#215;300 pixels: four times the size (and thus, the final resolution) of the screen version. This will give me a final resolution four times the original, or 288dpi, which I\u2019ve decided is sufficient for my aims. Your wants and needs may necessitate a larger image.<\/p>\n<p>Once I have my logo designed, I just save a large version, and then downsample a smaller version for the screen. I used the Save For Web feature of Photoshop to create a small version quickly, without having to mess with the original. I saved this version in color as well, but if you wanted, you could make the printer-friendly version grayscale so as to save on color ink. Again, it\u2019s your call.<\/p>\n<p><img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/cssdeck.com\/blog\/wp-content\/uploads\/2008\/07\/printfriendly2.gif\" alt=\"\" width=\"400\" height=\"278\" class=\"alignnone size-full wp-image-168\" \/><\/p>\n<p>Once we have the image, we can start in on the XHTML:<\/p>\n<pre lang=\"html4strict\" escaped=\"true\" line=\"1\">&lt;div id=&quot;logo&quot;&gt;\n\t&lt;img src=&quot;images\/logo-print.gif&quot; width=&quot;150&quot; height=&quot;75&quot; \/&gt;\n&lt;\/div&gt;<\/pre>\n<p>Simple, right? It bears explanation, though. The image inside our span is the printer-friendly, high resolution version of our image. However, the width and the height we\u2019ve set are based on the <em>low-resolution<\/em> 72dpi version. This is so our span takes up the correct amount of space on the screen.<\/p>\n<p>Now, we just have to hide the printer-friendly version and show the screen version:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">#logo {\n\tbackground: #fff url(images\/logo-screen.gif) no-repeat;\n\twidth: 150px;\n\theight: 75px; }\n#logo img {\n\tdisplay: none; }<\/pre>\n<p>The CSS above would go in your screen CSS file. It hides the image inside your span and displays a background image instead. The background image takes up the same number of pixels as the original, but it is scaled for 72dpi and displays perfectly on the screen.<\/p>\n<p>Now, all you have to do is either ensure the rules above do <strong>not<\/strong> exist in your print CSS file, or negate them in your print CSS with something like this:<\/p>\n<pre lang=\"css\" escaped=\"true\" line=\"1\">#logo {\n\tbackground: none; }\n#logo img {\n\tdisplay: block; }<\/pre>\n<p>And you should be set! When shown on the screen, the printer-friendly logo will be hidden with the \u201cdisplay: none\u201d rule, and the background image will be shown instead. But when printed, the background image won\u2019t show, and the larger image will be displayed. Because we\u2019ve forced it to display at a size of 150px by 75px, our image has an effective resolution of 72 x 4 = 288dpi, which will result in a much cleaner printed logo. And if the user has CSS disabled for any reason, the worst that will happen is they\u2019ll see the compressed high-res version on the screen instead of its low-res counterpart. The result will be a slightly jagged logo on the screen as the browser down-samples the original, but that is probably a small crime in the grand scheme of things.<\/p>\n<p>If you\u2019d like to see this in action, <a href=\"http:\/\/cssnewbie.com\/example\/print-friendly-images\/screen.html\">view the example page.<\/a> The first version has no fancy CSS image replacement going on. If you print the page, the logo should look fairly blurry. However, if you click through to <a href=\"http:\/\/cssnewbie.com\/example\/print-friendly-images\/print.html\">the second version<\/a> and print that page, you should see a noticeable difference in the printed result, but no real difference on the screen.<\/p>\n<p><a href=\"http:\/\/cssnewbie.com\/example\/print-friendly-images\/screen.html\" class=\"example\">View Example<\/a><\/p>\n<p>As I mentioned before, this technique has the possibility of eating up quite a bit of bandwidth, so it\u2019s probably best suited for smaller, important images. I wouldn\u2019t suggest rendering every image on your website this way. We don\u2019t want to create printer-friendliness at the expense of user-friendliness.<\/p>\n<div class=\"wp-socializer wpsr-share-icons \" data-lg-action=\"show\" data-sm-action=\"show\" data-sm-width=\"768\" ><h3>Share and Enjoy !<\/h3><div class=\"wpsr-si-inner\"><div class=\"wpsr-counter wpsrc-sz-32px\" style=\"color:#000\"><span class=\"scount\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook,twitter,linkedin,pinterest,print,pdf\">0<\/span><\/span><small class=\"stext\">Shares<\/small><\/div><div class=\"socializer sr-popup sr-32px sr-circle sr-opacity sr-pad sr-count-1 sr-count-1\"><span class=\"sr-facebook\"><a rel=\"nofollow\" href=\"https:\/\/www.facebook.com\/share.php?u=\" target=\"_blank\"  title=\"Share this on Facebook\"  style=\"color: #ffffff\" ><i class=\"fab fa-facebook-f\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"facebook\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-twitter\"><a rel=\"nofollow\" href=\"https:\/\/twitter.com\/intent\/tweet?text=%20-%20%20\" target=\"_blank\"  title=\"Tweet this !\"  style=\"color: #ffffff\" ><i class=\"fab fa-twitter\"><\/i><\/a><\/span>\n<span class=\"sr-linkedin\"><a rel=\"nofollow\" href=\"https:\/\/www.linkedin.com\/sharing\/share-offsite\/?url=\" target=\"_blank\"  title=\"Add this to LinkedIn\"  style=\"color: #ffffff\" ><i class=\"fab fa-linkedin-in\"><\/i><\/a><\/span>\n<span class=\"sr-pinterest\"><a rel=\"nofollow\" href=\"https:\/\/www.pinterest.com\/pin\/create\/button\/?url=&amp;media=&amp;description=\" target=\"_blank\"  title=\"Submit this to Pinterest\"  style=\"color: #ffffff\" data-pin-custom=\"true\"><i class=\"fab fa-pinterest\"><\/i><span class=\"ctext\"><span data-wpsrs=\"\" data-wpsrs-svcs=\"pinterest\">0<\/span><\/span><\/a><\/span>\n<span class=\"sr-print\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Print this article \"  style=\"color: #ffffff\" ><i class=\"fa fa-print\"><\/i><\/a><\/span>\n<span class=\"sr-pdf\"><a rel=\"nofollow\" href=\"https:\/\/www.printfriendly.com\/print?url=\" target=\"_blank\"  title=\"Convert to PDF\"  style=\"color: #ffffff\" ><i class=\"fa fa-file-pdf\"><\/i><\/a><\/span><\/div><\/div><\/div>","protected":false},"excerpt":{"rendered":"<p>One area where your website may look lackluster when printed is the images. It\u2019s a simple problem of resolution. Images are always displayed on the web at 72dpi (dots per inch). However, there&#8217;s a simple trick to sending a low-res version to the screen, and a high-res version to the printer. [&#8230;]<\/p>\n<p><a class=\"more-link article\" href=\"https:\/\/cssdeck.com\/blog\/print-friendly-images\/\" title=\"Click to read 'Print-Friendly Images and Logos with CSS'\">Read Article<\/a><\/p>\n","protected":false},"author":18,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[183,191],"tags":[],"_links":{"self":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/166"}],"collection":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/comments?post=166"}],"version-history":[{"count":0,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/posts\/166\/revisions"}],"wp:attachment":[{"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/media?parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/categories?post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cssdeck.com\/blog\/wp-json\/wp\/v2\/tags?post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}