{"id":532,"date":"2008-02-16T02:59:20","date_gmt":"2008-02-16T07:59:20","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/2008\/02\/16\/resizing-images-and-html\/"},"modified":"2008-02-16T02:59:20","modified_gmt":"2008-02-16T07:59:20","slug":"resizing-images-and-html","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2008\/02\/16\/resizing-images-and-html\/","title":{"rendered":"Resizing Images and HTML"},"content":{"rendered":"<p>This post is meant for webmasters, and it addresses a startlingly common problem: images included on pages and &#8220;resized&#8221; only in HTML.<\/p>\n<p>The basic tag to include an image, of course, is <tt><img decoding=\"async\" src=\"something.jpg\"><\/tt>. That will include <i>something.jpg<\/i> on the page.<\/p>\n<p>But say that the image is 1600&#215;1200 pixels (2.1 megapixels: big enough to fill your screen and then some, at least for most people). This is <i>way<\/i> too big to put on your webpage. So what do people do? They do something like <tt><img loading=\"lazy\" decoding=\"async\" src=\"something.jpg\" height=\"480\" width=\"640\"><\/tt> to resize it. <strong>This is a very, very bad way of doing it.<\/strong><\/p>\n<p>The problem is that this shows a fundamental misunderstanding of what the <tt>height<\/tt> and <tt>width<\/tt> attributes do. They&#8217;re essentially &#8216;hints&#8217; for the browser. The web browser, when it sees an image in your HTML, will download the whole image. In this case, it&#8217;ll download your 1600&#215;1200 image, which is probably about 500kB in size. (God help us if you have a whole series of these photographs on your page.) When it sees a mismatch between the specified <tt>height<\/tt> and <tt>width<\/tt> attributes, the browser will do a very rudimentary (read: very crappy) resize. So not only are you wasting a ton of bandwidth unnecessarily (which also makes your page load very slowly), but the end product is images that look horrible.<\/p>\n<p>Instead, open the image up in your editor of choice. Photoshop CS3 is <i>wonderful<\/i>, but those of us who can&#8217;t justify spending more than $500 on image editing software may prefer a free tool like <a href=\"http:\/\/www.getpaint.net\/\">Paint.NET<\/a>. Resize the image to the size you desire, and include <i>that<\/i> image, newly resized, on your page.<\/p>\n<p>You&#8217;ll see multiple improvements: your site will use less bandwidth, your pages will load much faster, and your images will look much better. (Also: I&#8217;d encourage you to simply omit the <tt>height<\/tt> and <tt>width<\/tt> attributes if you&#8217;re not sure what you&#8217;re doing. Writing perfect HTML, you&#8217;d set them to the image&#8217;s native dimensions, but so many people screw it up that it&#8217;s probably safest to just omit them. Every browser I&#8217;ve ever used has handled this seamlessly.)<\/p>","protected":false},"excerpt":{"rendered":"<p>This post is meant for webmasters, and it addresses a startlingly common problem: images included on pages and &#8220;resized&#8221; only in HTML. The basic tag to include an image, of course, is . That will include something.jpg on the page. &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2008\/02\/16\/resizing-images-and-html\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,8,18,22,24],"tags":[],"class_list":["post-532","post","type-post","status-publish","format-standard","hentry","category-computers","category-hero-of-the-day","category-ocd","category-programming","category-rants-raves"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/532","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=532"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/532\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=532"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=532"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=532"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}