{"id":3,"date":"2009-09-16T00:06:30","date_gmt":"2009-09-16T04:06:30","guid":{"rendered":"http:\/\/www.useragentman.com\/blog\/?p=3"},"modified":"2009-09-29T21:50:47","modified_gmt":"2009-09-30T01:50:47","slug":"optimizing-png-files-for-both-web-and-print","status":"publish","type":"post","link":"https:\/\/www.useragentman.com\/blog\/2009\/09\/16\/optimizing-png-files-for-both-web-and-print\/","title":{"rendered":"Optimizing PNG Files, for both Web and Print."},"content":{"rendered":"<div id=\"attachment_206\" class=\"wp-caption alignleft\" style=\"width: 238px;\"><a href=\"\/blogs\/wpdev\/files\/2009\/02\/shrinkingman.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-206\" src=\"\/images\/test\/shrinkingman-228x300.jpg\" alt=\"\" width=\"228\" height=\"300\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">The script included in this post can shrink your images down for easy handling.<\/p>\n<\/div>\n<p>Optimizing images is not only important for web applications, it is also important for reducing the size of print documents (e.g. Word Documents, PDFs, etc). This size is important not only when emailing them out, but also when embedding them into documents that you will be sharing with others.<\/p>\n<p>PNGs should be used for drawn images and screenshots (for photographs, it is better to use the JPEG file format).\u00a0 It uses a lossless compression algorithm, so what you save in your graphics editor is exactly what your users will see.\u00a0 It also supports features like <a href=\"http:\/\/en.wikipedia.org\/wiki\/Alpha_channel\">alpha channeling<\/a>.<\/p>\n<p>This article will show how to optimize images in this format.<\/p>\n<h2>A case study: Optimizing Screenshots<\/h2>\n<p>There are many times a web developer will need to produce screenshots of the work they do to send to clients. When I need to do this, I use the excellent <a title=\"Screengrab homepage.\" href=\"http:\/\/www.screengrab.org\/\"><span style=\"color: #888888;\">Screengrab Firefox Addon<\/span><\/a>, since it is so easy to use. I will first talk about how to take screenshots using this tool, and in the next section, talk about how to optimize the PNG files they produce. (<strong>Note:<\/strong> If you need to take screenshots using Internet Explorer, I would suggest using The GIMP\u2019s screenshot feature to do this. There is a great <a href=\"http:\/\/www.nwe.ufl.edu\/writing\/help\/graphics\/gimp\/screenshots.shtml\"> simple tutorial on how to do screenshots with the GIMP<\/a> at the <a href=\"http:\/\/www.nwe.ufl.edu\/writing\/\"><span>The Networked Writing Environment at the University of Florida<\/span><\/a> website).<\/p>\n<h3>Using Screengrab<\/h3>\n<p>After you install this tool, all you have to do is right click the document you want to take a screenshot of and you will get the following menu.<\/p>\n<div id=\"attachment_59\" class=\"wp-caption aligncenter\" style=\"width: 310px;\"><a href=\"http:\/\/dt09101.mtsallstream.com\/blogs\/files\/2009\/02\/screengrab.jpg\"><br \/>\n<img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-59\" src=\"\/images\/test\/screengrab-300x132.jpg\" alt=\"\" width=\"300\" height=\"132\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Right-click any web page<br \/>\nto produce a screen capture of any page.<\/p>\n<\/div>\n<h3>How to reduce image data size<\/h3>\n<p>I created <a href=\"\/public\/scripts\/compressingImagesEffectively.zip\">a script<\/a> that would reduce this file size as much as possible. How does this script work:<\/p>\n<ol>\n<li>It first uses <a title=\"The Imagemagick home page.\" href=\"http:\/\/www.imagemagick.org\/script\/index.php\">ImageMagick <\/a> to reduce the amount of colour-palette inside the image to 256, since Screengrab will usually create 16-bit images (which have millions of colours).  This usually results in 25% reduction of the size of the image and the extra colours aren\u2019t missed when these images are inside a Word Document because the physical dimensions of these images are smaller than the actual page itself.<\/li>\n<li>It then uses two command line tools, <a title=\"optipng homepage. \" href=\"http:\/\/optipng.sourceforge.net\/\">optipng<\/a> and <a title=\"AdvanceCOMP homepage, which advpng is a part of.\" href=\"http:\/\/advancemame.sourceforge.net\/comp-readme.html\"> advpng<\/a>, to compress the image further. It uses these programs in a variety of ways to see which is the most optimal, and saves the smallest result. This usually results to a further 30-40% reduction is data size.<\/li>\n<\/ol>\n<p>Together, it is possible to reduce an image to 50-70% of it\u2019s original size. Not bad for a script done in my spare time.<\/p>\n<p>An <a href=\"\/public\/scripts\/compressingImagesEffectively.zip\">archive with this script and supporting files<\/a> is available here. This archive includes:<\/p>\n<ul>\n<li>reduceColours: the script that reduces the images to 256 colours.<\/li>\n<li>compressPng: the script that optimizes the PNG image<\/li>\n<li>optimizeImagesForPrint: the script that executes reduceColours and compressPng in one step.<\/li>\n<li>optipng.exe and advpng.exe, the actual file compressors used by compressPng.<\/li>\n<\/ul>\n<p>Note that in order to use this script under Windows, you must have Cygwin installed on your machine. If you don\u2019t know how to do this, read <a title=\"A step-by-step how-to to installing Cygwin.\" href=\"http:\/\/www.soe.ucsc.edu\/%7Eyou\/notes\/cygwin-install.html\"> Installing Cygwin<\/a>. Make sure you install ImageMagick using the Cygwin installer, since is needed for the reduceColours script.<\/p>\n<p>If you run Mac OS X, Linux, FreeBSD or any other UNIX variant, you should be able to run this script as long as you are comfortable with the command line.\u00a0 Note that you will have to download optipng and advpng separately, since the archive only contains the Windows binaries of these programs.<\/p>\n<p>To run the optimizer, use the following syntax inside a bash shell:<\/p>\n<blockquote class=\"shell\">\n<pre>optimizeImagesForPrint &lt;imageList&gt;<\/pre>\n<\/blockquote>\n<p>It will create a directory called optimized that will contain all the optimized images. If you just want to reduce the images to 256 colours, or optimize 16-bit images without reducing the colours, use reduceColours and compressPng in the same manner.<\/p>\n<h2>Conclusions<\/h2>\n<p>Even though this article has focused on embedding PNG images into documents, the ideas here can be used when optimizing PNGs for the web.  There may be cases where you don&#8217;t want to reduce the amount of colours &#8212; feel free to change the script to do that.<\/p>\n<p>Please let me know if you find any bugs or if you find other\/better ways to optimize images.<\/p>\n<p><a title=\"PNG Image Compression Script.\" href=\"\/public\/scripts\/compressingImagesEffectively.zip\"><br \/>\nThe scripts are available here in a handy zip archive<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Optimizing images is not only important for web applications, it is also important for reducing the size of print documents. This article will show how to optimize images in the PNG format.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23],"tags":[25,26,24],"class_list":["post-3","post","type-post","status-publish","format-standard","hentry","category-images","tag-firefox-screengrab","tag-image-optimization","tag-png-compression"],"_links":{"self":[{"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/posts\/3","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/comments?post=3"}],"version-history":[{"count":22,"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/posts\/3\/revisions"}],"predecessor-version":[{"id":6,"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/posts\/3\/revisions\/6"}],"wp:attachment":[{"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/media?parent=3"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/categories?post=3"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.useragentman.com\/blog\/wp-json\/wp\/v2\/tags?post=3"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}