<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>User Agent Man &#187; Images</title>
	<atom:link href="http://www.useragentman.com/blog/category/technologies/images/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.useragentman.com/blog</link>
	<description>A Blog about Client Side Web Technology</description>
	<lastBuildDate>Thu, 26 Jan 2012 03:14:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Cross Browser CSS cursor Images In Depth</title>
		<link>http://www.useragentman.com/blog/2011/12/21/cross-browser-css-cursor-images-in-depth/</link>
		<comments>http://www.useragentman.com/blog/2011/12/21/cross-browser-css-cursor-images-in-depth/#comments</comments>
		<pubDate>Wed, 21 Dec 2011 05:34:31 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS3]]></category>
		<category><![CDATA[cursor]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[custom cursors]]></category>
		<category><![CDATA[IE]]></category>
		<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3893</guid>
		<description><![CDATA[<img src="/blog/wp-content/uploads/2011/12/intro.png" /> When used properly, custom CSS cursors can add a little bit of polish to your web sites and applications.  However, doing this in a cross browser way can be a little confusing unless you know all the gotchas, and this article will go into depth about them.   We will also explore issues such as when to use custom cursors, performance, what makes good cursor design, cursor file formats, and cursor size.]]></description>
			<content:encoded><![CDATA[
<!--
        This notice is required for the CanvasPainer widget below.

	Copyright (c) 2005, 2006 Rafael Robayna

	Permission is hereby granted, free of charge, to any person obtaining 
	a copy of this software and associated documentation files (the "Software"), 
	to deal in the Software without restriction, including without limitation 
	the rights to use, copy, modify, merge, publish, distribute, sublicense, 
	and/or sell copies of the Software, and to permit persons to whom the Software 
	is furnished to do so, subject to the following conditions:
	
	The above copyright notice and this permission notice shall be included
	in all copies or substantial portions of the Software.

	THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
	EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 
	OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
	IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
	DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
	OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 
	OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

	Additional Contributions by: Morris Johns
-->


<div id="canvasPainter">
<div id="controls">
  <div class="ctr_btn" id="btn_1" >brush 2</div> 
  <div class="ctr_btn" id="btn_2" >line</div> 
  <div class="ctr_btn" id="btn_3" >rectangle</div> 
  <div class="ctr_btn" id="btn_4" >circle</div> 
  <div class="ctr_btn" id="btn_5" >clear</div> 
  <div class="ctr_btn" id="btn_9">new</div>
  <input class="color" id="color" value="#ff3333"></div>
<canvas id="canvas" width="200" height="200"></canvas>
<canvas id="canvasInterface" width="200" height="200"></canvas>
<p class="description"><small>Paint widget a remix of <a href="http://caimansys.com/painter/">CanvasPainter</a> © <a href="http://caimansys.com/">Rafael Robayna</a></small></p>
</div>
<p><strong>If you are using a desktop browser (except for Opera), play with the paint widget on the left.</strong>  When you select a tool and mouse over the white canvas, your mouse arrow will change to a custom cursor representing that tool (&agrave; la Photoshop or The GIMP).  This is not done by creating a DOM object and moving it to the mouse&#8217;s coordinates &mdash; we are using CSS to do it using the <code>cursor</code> property&#8217;s <code>url()</code> function. <strong> When used properly, custom CSS cursors can add a little bit of polish</strong> to your web sites and applications.  However, <strong>doing this in a cross browser way can be a little confusing</strong> unless you know all the gotchas, and this article will go into depth about them.   We will also explore issues such as <strong>when to use custom cursors, performance, what makes good cursor design, cursor file formats, and cursor size.</strong></p>
<h2>When Should I Use Custom Cursors Instead of the Built-in Ones?</h2>
<p>In general, CSS cursors (built-in or custom) should be used as a hint to the user as to what action the mouse can perform.  Let&#8217;s take a look at an example that doesn&#8217;t use custom cursors to illustrate a common use-case: drag and drop.  To give users a visual cue that an item is draggable, it is common practice to set an object&#8217;s CSS <code>cursor</code> property to <code>move</code>.  Mouse over the object draggable object below to see how this works. </p>
<div id="container">
<a href="#" id="toDrag" draggable="true">Drag me!</a>
</div>
<p>This is done with the following CSS:</p>
<blockquote class="code">
<pre>
a[draggable="true"] {
    cursor: move;
}
</pre>
</blockquote>
<p>The code above ensure that when a user &#8220;mouses over&#8221; a link with the HTML5 Drag and Drop &#8220;draggable&#8221; attribute, the <code>move</code> cursor appears.  It is a great way to help the user &#8220;figure out&#8221; how to use the user interface with minimal instruction.  A list of the built-in cross-browser cursor property values can be seen at <a href="http://www.quirksmode.org/css/cursor.html">CSS2 Cursor Style Page</a>.</p>
<p>The built-in cursors are great, but there are a few things to keep in mind.</p>
<ul>
<li><strong>Built-in cursors may look different depending on what browser/operating system is being used</strong>.  For example, some browsers (e.g. Firefox on Windows 7) will show the <code>move</code> cursor as a four-pointed arrow (<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/move_cursor.png" alt="[Four-Pointed Arrow Cursor]" class="inline" />) while others (e.g. Firefox on Mac OS X) will show a hand (<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/12/cursor-hand.png" alt="[Hand Cursor]" class="inline" />).  Using custom cursors, you can ensure all applications are using the same cursor for a more consistent expeience.  The example below is the same as the one above, except in all browsers, you will see the a hand icon.
<div id="container2">
<a href="#" id="toDrag2" draggable="true">Drag me!</a>
</div>
</li>
<li><strong>Not all browsers support all the same &#8220;built-in&#8221; cursors, and custom cursors allows you to add support for them.</strong> For example, <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=258960">while Firefox on Windows doesn&#8217;t support <code>context-menu</code></a>, it seems to be the only browser that <a href="https://developer.mozilla.org/en/CSS/-moz-zoom-in">supports the zoom-in and -out cursors</a>.  Using custom cursors, you can implement all of these in all browsers.</li>
<li><strong>There may not be a built-in cursor for the use-case you need to solve.</strong>  A good example is in the paint widget at the beginning of this article &mdash; none of those cursors exist natively in any browser.</li>
<li><strong>It&#8217;s nice to design your own cursors</strong>, since sometimes the built-in ones may be a little basic looking (If you do this, please keep in mind that users are used to the built in ones, so your custom cursor shouldn&#8217;t look too much different than them if you want your application to be easy-to-use).
</ul>
<h2>The CSS of Custom Cursors</h2>
<p>Here is some sameple CSS code that will show custom cursor when the user mouses over a <code>div</code> with an id of <code>dragMe</code>.  If the browser doesn&#8217;t do custom cursors (like Opera), the cursor fallback to the built-in <code>move</code> cursor.</p>
<blockquote class="code">
<pre>
#dragMe {
    cursor: url('customMoveCursor.cur'), move;
}
</pre>
</blockquote>
<p><strong>As long as your cursor is in the same directory as your stylesheet, and as long as it is an uncompressed .CUR file, it&#8217;s as simple as that.</strong> Note that <a href="http://en.wikipedia.org/wiki/ICO_%28file_format%29">a .CUR file is just an .ICO file with extra information</a> that allows the developer to define the &#8220;host spot&#8221; position of the cursor (i.e. the part of the image which points to the position of the mouse).  Note that <strong>.CUR files support 32-bit color</strong> (16.7 million colors plus alpha channel transparency), so designers can create cursors that have semitransparent areas like shadows and anti-aliasing.   </p>
<p><strong>How does one create a .CUR file?</strong> Not too many graphic tools create .CUR files natively, but there are some easy solutions. If you are a Photoshop user, the <a href="http://www.telegraphics.com.au/svn/icoformat/trunk/dist/README.html">ICO (Windows Icon) file format plugin for Photoshop</a> is what you are looking for (I have not used it myself, but it apparently can save .CUR files directly.  Any comment on how well this works would be most welcome). If, like me, you use the GIMP, simply save the file as a .ICO file and convert it with <a href="http://www.janthor.com/sketches/index.php?/archives/10-A-Python-script-to-convert-ICO-to-CUR-files.html">this command line tool written in Python</a> by <a href="http://www.janthor.com">Jan Thor</a>. </p>
<h2>The Gotchas of Custom CSS Cursors</h2>
<p>There are a few things you need to remember when using CSS cursors</p>
<ol>
<li><strong>You must add a default &#8220;built-in&#8221; cursor after your custom cursor,</strong> or the custom cursor will not load in Firefox.  Think of it as Mozilla&#8217;s way of enforcing good web practices. :-)</li>
<li><strong>Internet Explorer interprets relative URLs as <em>relative to the HTML document</em></strong>, and not the CSS file like God (and the W3C) intended (Sometimes it seems that IE goes out of its way to make lives difficult for us developers).  This is true for all versions of IE, even IE9. To ensure cross-browser compatibility, you must either use an absolute URL:<br />
<blockquote class="code">
<pre>
#dragMe {
    cursor: url('/cursors/customMoveCursor.cur'), move;
}
</pre>
</blockquote>
<p>or a fallback url for IE:</p>
<blockquote class="code">
<pre>
/*
 * Assume this the HTML is in a directory above this CSS file
 */

#dragMe {
    cursor: url('../cursors/customMoveCursor.cur'),     /* Modern browsers    */
            url('cursors/customMoveCursor.cur'),        /* Internet Explorer  */
            move;                                       /* Older browsers     */
}
</pre>
</blockquote>
</li>
<li><strong>It is best that your .CUR files are 32&#215;32 pixels in size.</strong>  IE9 seems to resize cursors that are smaller than this to 32&#215;32, and IE8 and under cannot show cursors larger than this size.  While it is true that you can fit multiple file sizes inside a .CUR file, sticking with one 32&#215;32 image will ensure cross-browser consistency.</li>
<li>Although .CUR files can be saved in either a compressed or uncompressed format, <strong>not all browsers can read the compressed ones</strong>.  It is best to save your cursors in uncompressed format.  If you are using the GIMP to save to .ICO format first before you convert to .CUR, make sure that the .ICO is saved without compression.</li>
</ol>
<h2>Performance Issues</h2>
<p>As mentioned earlier, a lot of browsers (like Firefox or IE6) cannot show <em><strong>compressed</strong></em> .CUR files, but they can show .PNG files.  Since we would like to use a compressed version if possible, one could do this:</p>
<blockquote class="code">
<pre>
#dragMe {
    cursor: url('/cursors/customMoveCursor.png'),      /* Modern browsers    */
            url('/cursors/customMoveCursor.cur'),      /* Internet Explorer  */
            move;                                      /* Older browsers     */
}
</pre>
</blockquote>
<p><strong>This works well as long as the cursor hotspot is 0,0.</strong>  You can define a PNG hotspot using the CSS3 cursor syntax, but it breaks IE:</strong></p>
<blockquote class="code">
<pre>
#dragMe {
    cursor: url('customMoveCursor.png') 5 15, /* Modern browsers, hotspot is (5, 15)            */
            url('customMoveCursor.cur'),      /* IE chokes on the above line .. never gets here */
            move;                             /* Older browsers (IE never gets here either)     */
}
</pre>
</blockquote>
<p>In order to fix this issue, one must you conditional comments to make a separate IE from everyone else.  Let&#8217;s use a variation of <a href="http://paulirish.com/2008/conditional-stylesheets-vs-css-hacks-answer-neither/">Paul Irish&#8217;s Conditional Comment pattern</a> to do this.  Change the <code>html</code> tag to this:</p>
<blockquote class="code">
<pre>
&lt;!--[if (lte IE 9) ]&gt;&lt;html class="ie9 oldIE"&gt;    &lt;![endif]--&gt;
&lt;!--[if (gt IE 9)  ]&gt;&lt;html class="modern"&gt;       &lt;![endif]--&gt;
&lt;!--[!(IE)]&gt;&lt;!--&gt;    &lt;html class="notIE modern"&gt; &lt;!--&lt;![endif]--&gt;
</pre>
</blockquote>
<p>Now we can use this CSS to ensure .PNG loads in non-IE browsers:</p>
<blockquote class="code">
<pre>
html.modern #dragMe {
  cursor: url('customMoveCursor.png') 5 15, /* Modern browsers, hotspot is (5, 15).   */
          move;                             /* Older browsers                         */
}

html.oldIE #dragMe {
  cursor: url('customMoveCursor.cur'),      /* IE .CUR file loads                     */
          move;                             /* In case IE can't load the above.       */
}
</pre>
</blockquote>
<p>The extra bytes used to create the conditional comments may or may not be worth the trouble.  If you are using conditional comments (like I do all the time), it may be worth it.</p>
<h2>A Final Word On Testing in IE </h2>
<p>If you edit a .cur file on the web server and reload your page with that cursor in Internet Explorer, you may not see the edited change, since <strong>IE has kept the older cursor in cache and has a hard time letting go</strong>, kind of like <a href="http://www.youtube.com/watch?v=MBHOL1PcPR8">that person you dated in high-school</a>.  You will need to clear IE&#8217;s cache in order to see the new cursor.  This is quite annoying, and it is something you should keep in mind when troubleshooting in IE.</li>
</ul>
<h2>Further Reading</h2>
<ul>
<li><a href="http://beradrian.wordpress.com/2008/01/08/cross-browser-custom-css-cursors/">Cross-browser custom CSS cursors</a> by <a href="http://beradrian.wordpress.com/">Adrian Ber</a></li>
</ul>
<p><script type="text/javascript">
doOnLoad()
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/12/21/cross-browser-css-cursor-images-in-depth/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Clipping JPEG Images Into Non-Rectangular Polygons Using polyClip.js</title>
		<link>http://www.useragentman.com/blog/2011/10/29/clipping-jpeg-images-into-non-rectangular-polygons-using-polyclip-js/</link>
		<comments>http://www.useragentman.com/blog/2011/10/29/clipping-jpeg-images-into-non-rectangular-polygons-using-polyclip-js/#comments</comments>
		<pubDate>Sat, 29 Oct 2011 15:20:29 +0000</pubDate>
		<dc:creator>zoltan</dc:creator>
				<category><![CDATA[canvas]]></category>
		<category><![CDATA[HTML5]]></category>
		<category><![CDATA[Images]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[jQuery]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[VML]]></category>
		<category><![CDATA[arbitrary clipping]]></category>
		<category><![CDATA[clipping]]></category>
		<category><![CDATA[non-rectangular clipping. polygon clipping]]></category>
		<category><![CDATA[polyClip]]></category>
		<category><![CDATA[polygon]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3526</guid>
		<description><![CDATA[<img src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissorsTeaser.jpg" /> Up until now, if a developer needed to clip an image in a non-rectangular shape, it was necessary to save the image as a PNG with an alpha channel. If the image is a photograph, the file-size balloons up to unacceptable levels. My new library, polyClip.js, allows developers to clip these images using photograph friendly JPEGs instead. This article guides you step by step on how to use it yourself.]]></description>
			<content:encoded><![CDATA[<div class="box">
<div id="explanation1">This photo is not a PNG image with an alpha channel.</div>
<div id="explanation2"><a href="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.jpg">It is a JPEG</a> that has been clipped with polyClip.js</div>
<div id="explanation3">
<p>The text was rotated using CSS3 Transforms, with alternate CSS for older IE using the <a href="http://www.useragentman.com/IETransformTranslator">IE Transform Translator</a>.  Original photo by <a href="http://www.flickr.com/photos/free-stock/4816852597/">Emilian Robert Vicol</a> clipped with polyClip.js</p>
</p></div>
<div class="clipParent"><img data-polyclip=" 0,0,45,3,55,8,64,18,74,24,80,32,86,45,82,32,83,38,86,46,88,52,90,62,90,68,91,76,91,82,91,83,103,87,112,91,121,97,127,102,133,106,136,112,138,116,139,121,139,122,147,125,154,127,163,129,178,131,190,132,204,132,210,131,225,124,286,107,332,96,370,88,401,83,425,79,450,76,457,77,456,80,446,85,430,91,406,99,383,108,365,114,352,119,384,117,416,116,453,114,472,113,474,113,472,118,446,126,419,132,390,138,362,144,343,148,307,153,282,157,266,159,245,160,234,160,219,160,209,163,198,167,182,175,170,183,158,194,156,195,157,201,157,204,157,204,157,210,153,219,148,229,143,236,137,244,132,250,124,258,118,263,113,267,98,276,87,281,77,283,0,284,1,191,10,190,16,191,20,191,21,192,28,191,37,190,39,189,38,190,40,190,48,190,53,191,57,191,69,188,77,187,91,183,109,179,127,173,146,166,162,158,173,153,158,151,144,150,127,151,105,152,86,154,66,157,53,160,49,161,46,165,44,167,41,168,33,168,28,167,28,166,21,170,16,171,11,171,4,170,0,168" src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.jpg" alt=""  width="480" height="360" class="alignleft size-full wp-image-3771" /></div>
</div>
<p>There have been many times I have come across the need to <strong>take an image and cut an irregular shape out of it.</strong>  Normally, when a developer comes across this requirement, the only thing to do is to open the image up with your favorite graphics editor, use the select tool to cut out the shape you want, and then save the result as a <a href="http://en.wikipedia.org/wiki/Portable_Network_Graphics">PNG</a>, since it is the only image format used by all web browsers that support alpha channels.  The problem is that <strong>PNG images, while compressed, are not as small as <a href="http://en.wikipedia.org/wiki/Jpeg">JPEGs</a> if the source image is a photograph</strong>, and the download time of a page can balloon to unacceptable levels if there are many of these types of image on a page.  When I first came across this problem, I didn&#8217;t think there was an obvious solution, but after a lot of thought, I created <strong>a library that uses <a href="http://en.wikipedia.org/wiki/HTML_canvas">HTML5 <code>canvas</code></a> to clip a JPEG </strong> (or any other image for that matter).  <strong>The library also supports older versions of IE</strong> (7-8) using the <a href="http://excanvas.sourceforge.net/">Excanvas JavaScript library</a> which polyfills <code>canvas</code> using <a href="http://en.wikipedia.org/wiki/Vector_Markup_Language">VML</a>.</p>
<h2>Okay, How Can I Do The Same Thing?</h2>
<ul>
<li><a href="https://github.com/zoltan-dulac/polyClip">Download my script from github</a> (It includes jQuery 1.6.4 and excanvas release 3.  It should work with later versions &mdash; if it doesn&#8217;t, please let me know and I&#8217;ll fix it ;-) ) .</li>
<li>Include them into the head of your document.<br />
<blockquote class="code">
<pre>
  &lt;script src="/path/to/js/jquery-1.6.2.min.js"&gt;&lt;/script&gt;

  &lt;!--[if lt IE 9 ]&gt;
   &lt;script src="/path/to/js/excanvas/excanvas.compiled.js"&gt;&lt;/script&gt;
  &lt;![endif]--&gt;

  &lt;script src="/path/to/js/polyClip-p.js"&gt;&lt;/script&gt;
</pre>
</blockquote>
</li>
<li>Layout your page as normal, placing <code>img</code> tags where you want the clipped images to go:<br />
<blockquote class="code">
<pre>
&lt;div class="clipParent"&gt;
  &lt;img src="images/image.jpg" /&gt;
&lt;/div&gt;
</pre>
</blockquote>
<p><strong>Note the <code>div</code> tag with the class of <code>clipParent</code></strong>.  You must surround all the image tags with <code>data-polyclip</code> attributes set one.  This is so you can style the image correctly, since the library will remove the image tag and replace it with a <code>canvas</code> element.
</p></blockquote>
</li>
<li>For every image on your page that you want to clip, calculate the points of the shape you want to cut out of the image and place them in the <code>data-polyclip</code> attribute.  For example, let&#8217;s say you have the following shape you want to cut out of a photograph:
<div class="centered ghost">
  <img src="/tests/polyClip/images/crop.jpg"   />
</div>
<div class="clipParent centered inFront">
  <img src="/tests/polyClip/images/crop.jpg" data-polyclip="487, 4, 500, 239, 19, 239, 43, 195" data-stroke="rgb(0, 0, 0)" /></p>
<div class="point" id="pt1" style="left: 487px; top: 4px; "><span>(487, 4)</span></div>
<div class="point" id="pt2" style="left: 500px; top: 239px"><span>(500, 239)</span></div>
<div class="point" id="pt3" style="left: 19px; top: 239px"><span>(19, 239)</span></div>
<div class="point" id="pt4" style="left: 43px; top: 195px; "><span>(43, 195)</span></div>
</div>
<p>You would then just set the <code>data-polyclip</code> attribute to those points:</p>
<blockquote class="code">
<pre>
&lt;img src="image.jpg" <span class="hilite">data-polyclip="487, 4, 500, 239, 19, 239, 43, 195"</span> /&gt;
</pre>
</blockquote>
<p>Note that the point co-ordinates are comma delimited.  If you don&#8217;t want to calculate these numbers by hand, you can use your favorite imagemap generation tool to do generate the list of coordinates.  Just remember to take the coordinates out of the imagemap code and stick it in the <code>data-polyclip</code> attribute (for the examples on this page, I used the on-line tool available at <a href="http://www.image-maps.com">image-maps.com</a>).</li>
</ul>
<h2>Why Should I Do This Instead of Using a PNG?</h2>
<p>Compare the image above with a PNG clipped with the GIMP.   Even when I compressed the PNG with <a href="http://www.useragentman.com/blog/2009/09/16/optimizing-png-files-for-both-web-and-print/">my PNG optimization script</a>, the 191K PNG file is huge compared to it&#8217;s tiny 18K polyclipped JPEG analogue (<strong>Note:</strong> file sizes refer to the size of the full image as displayed at the top of this article):</p>
<table class="dataTable">
<thead>
<tr>
<th>JPG using polyClip.js (18K)</th>
<th>PNG (191K)</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="clipParent"><img data-polyclip="0,0,55,0,64,4,70,12,80,22,82,32,86,45,82,32,83,38,86,46,88,52,90,62,90,68,91,76,91,82,91,83,103,87,112,91,121,97,127,102,133,106,136,112,138,116,139,121,139,122,147,125,154,127,163,129,178,131,190,132,204,132,210,131,225,124,286,107,332,96,370,88,401,83,425,79,450,76,457,77,456,80,446,85,430,91,406,99,383,108,365,114,352,119,384,117,416,116,453,114,472,113,474,113,472,118,446,126,419,132,390,138,362,144,343,148,307,153,282,157,266,159,245,160,234,160,219,160,209,163,198,167,182,175,170,183,158,194,156,195,157,201,157,204,157,204,157,210,153,219,148,229,143,236,137,244,132,250,124,258,118,263,113,267,98,276,87,281,77,283,0,284,1,191,10,190,16,191,20,191,21,192,28,191,37,190,39,189,38,190,40,190,48,190,53,191,57,191,69,188,77,187,91,183,109,179,127,173,146,166,162,158,173,153,158,151,144,150,127,151,105,152,86,154,66,157,53,160,49,161,46,165,44,167,41,168,33,168,28,167,28,166,21,170,16,171,11,171,4,170,0,168" src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.jpg" alt=""  width="480" height="360" class="alignleft size-full wp-image-3771" /></div>
</td>
<td>
<div class="pngImage">
  <img src="http://www.useragentman.com/blog/wp-content/uploads/2011/10/scissors.png" />
  </div>
</td>
</tr>
</tbody>
</table>
<p>You may ask whether the amount of JavaScript used in this solution is greater than the bandwidth saved by using JPEG compression.  <strong>Not including jQuery, the amount of JavaScript clocks in at 2K or 13K</strong>, depending on the browser used (2K for the compressed polyClip script and 11K for excanvas, which will only be loaded by IE7-8). Although jQuery adds 91K to this equation, it doesn&#8217;t matter that much to me personally since I am probably using it for other parts of my page anyways.  <strong>Even with jQuery, the amount of JavaScript downloaded outweighs using a PNG,</strong> especially if your are clipping a larger image or a huge amount of smaller images.</p>
<p><a class="exampleLink" href="https://github.com/zoltan-dulac/polyClip">Download the latest version of polyClip.js from github.</a></p>
<h2>A Few Caveats</h2>
<ul>
<li>In IE7 and 8, the image may appear briefly as a black outline before the image appears. Other than that, it looks about the same as the other browsers.</li>
<li>The image does not show up correctly in Opera Mini.  Then again, a lot of things (e.g. CSS3 text-shadows, CSS3 Transforms, etc.) don&#8217;t show up correctly in Opera Mini. :-)</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2011/10/29/clipping-jpeg-images-into-non-rectangular-polygons-using-polyclip-js/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Optimizing PNG Files, for both Web and Print.</title>
		<link>http://www.useragentman.com/blog/2009/09/16/optimizing-png-files-for-both-web-and-print/</link>
		<comments>http://www.useragentman.com/blog/2009/09/16/optimizing-png-files-for-both-web-and-print/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 04:06:30 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Images]]></category>
		<category><![CDATA[firefox screengrab]]></category>
		<category><![CDATA[image optimization]]></category>
		<category><![CDATA[png. compression]]></category>

		<guid isPermaLink="false">http://www.useragentman.com/blog/?p=3</guid>
		<description><![CDATA[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.]]></description>
			<content:encoded><![CDATA[<div id="attachment_206" class="wp-caption alignleft" style="width: 238px;"><a href="/blogs/wpdev/files/2009/02/shrinkingman.jpg"><img class="size-medium wp-image-206" src="/images/test/shrinkingman-228x300.jpg" alt="" width="228" height="300" /></a></p>
<p class="wp-caption-text">The script included in this post can shrink your images down for easy handling.</p>
</div>
<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>
<p>PNGs should be used for drawn images and screenshots (for photographs, it is better to use the JPEG file format).  It uses a lossless compression algorithm, so what you save in your graphics editor is exactly what your users will see.  It also supports features like <a href="http://en.wikipedia.org/wiki/Alpha_channel">alpha channeling</a>.</p>
<p>This article will show how to optimize images in this format.</p>
<h2>A case study: Optimizing Screenshots</h2>
<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’s 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>
<h3>Using Screengrab</h3>
<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>
<div id="attachment_59" class="wp-caption aligncenter" style="width: 310px;"><a href="http://dt09101.mtsallstream.com/blogs/files/2009/02/screengrab.jpg"><br />
<img class="size-medium wp-image-59" src="/images/test/screengrab-300x132.jpg" alt="" width="300" height="132" /></a></p>
<p class="wp-caption-text">Right-click any web page<br />
to produce a screen capture of any page.</p>
</div>
<h3>How to reduce image data size</h3>
<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>
<ol>
<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’t missed when these images are inside a Word Document because the physical dimensions of these images are smaller than the actual page itself.</li>
<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>
</ol>
<p>Together, it is possible to reduce an image to 50-70% of it’s original size. Not bad for a script done in my spare time.</p>
<p>An <a href="/public/scripts/compressingImagesEffectively.zip">archive with this script and supporting files</a> is available here. This archive includes:</p>
<ul>
<li>reduceColours: the script that reduces the images to 256 colours.</li>
<li>compressPng: the script that optimizes the PNG image</li>
<li>optimizeImagesForPrint: the script that executes reduceColours and compressPng in one step.</li>
<li>optipng.exe and advpng.exe, the actual file compressors used by compressPng.</li>
</ul>
<p>Note that in order to use this script under Windows, you must have Cygwin installed on your machine. If you don’t 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>
<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.  Note that you will have to download optipng and advpng separately, since the archive only contains the Windows binaries of these programs.</p>
<p>To run the optimizer, use the following syntax inside a bash shell:</p>
<blockquote class="shell">
<pre>optimizeImagesForPrint &lt;imageList&gt;</pre>
</blockquote>
<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>
<h2>Conclusions</h2>
<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>
<p>Please let me know if you find any bugs or if you find other/better ways to optimize images.</p>
<p><a title="PNG Image Compression Script." href="/public/scripts/compressingImagesEffectively.zip"><br />
The scripts are available here in a handy zip archive</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.useragentman.com/blog/2009/09/16/optimizing-png-files-for-both-web-and-print/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

