<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Load a photo in a canvas, then flip</title>
	<atom:link href="http://www.phpied.com/photo-canvas-tag-flip/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.phpied.com/photo-canvas-tag-flip/</link>
	<description>Stoyan&#039;s blog about &#60;a href=&#34;/category/xhtml&#34; class=&#34;tag-minor&#34;&#62;(x)html(5)&#60;/a&#62;, &#60;a href=&#34;/category/ajax&#34; class=&#34;tag-major&#34;&#62;ajax&#60;/a&#62;, &#60;a href=&#34;/category/bookmarklets&#34; class=&#34;tag-major&#34;&#62;bookmarklets&#60;/a&#62;, &#60;a href=&#34;/category/browsers&#34; class=&#34;tag-minor&#34;&#62;browsers&#60;/a&#62;, &#60;a href=&#34;/category/css&#34; class=&#34;tag-normal&#34;&#62;css&#60;/a&#62;, &#60;a href=&#34;/category/firebug&#34; class=&#34;tag-minor&#34;&#62;firebug&#60;/a&#62;, &#60;a href=&#34;/category/javascript&#34; class=&#34;tag-numero-uno&#34;&#62;javascript&#60;/a&#62;, &#60;a href=&#34;/category/json&#34; class=&#34;tag-normal&#34;&#62;json&#60;/a&#62;, &#60;a href=&#34;/category/mdb2&#34; class=&#34;tag-minor&#34;&#62;mdb2&#60;/a&#62;, &#60;a href=&#34;/category/mysql&#34; class=&#34;tag-normal&#34;&#62;mysql&#60;/a&#62;, &#60;a href=&#34;/category/pear&#34; class=&#34;tag-numero-uno&#34;&#62;pear&#60;/a&#62;, &#60;a href=&#34;/category/performance&#34; class=&#34;tag-major&#34;&#62;performance&#60;/a&#62;, &#60;a href=&#34;/category/php&#34; class=&#34;tag-numero-uno&#34;&#62;php&#60;/a&#62;, &#60;a href=&#34;/category/phpbb&#34; class=&#34;tag-major&#34;&#62;phpbb&#60;/a&#62;, &#60;a href=&#34;/category/tools&#34; class=&#34;tag-normal&#34;&#62;tools&#60;/a&#62;, &#60;a href=&#34;/category/yslow&#34; class=&#34;tag-minor&#34;&#62;yslow&#60;/a&#62;, &#60;a href=&#34;/category/yui&#34; class=&#34;tag-normal&#34;&#62;yui&#60;/a&#62;, &#60;a href=&#34;/category/writing&#34; class=&#34;tag-minor&#34;&#62;writing&#60;/a&#62;, &#60;a href=&#34;/category/music&#34; class=&#34;tag-major&#34;&#62;music&#60;/a&#62;,... &#60;a href=&#34;/category/life-and-everything&#34; class=&#34;tag-normal&#34;&#62;life and everything&#60;/a&#62;.</description>
	<lastBuildDate>Sat, 11 Feb 2012 14:07:43 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1</generator>
	<item>
		<title>By: Antaranian</title>
		<link>http://www.phpied.com/photo-canvas-tag-flip/#comment-71624</link>
		<dc:creator>Antaranian</dc:creator>
		<pubDate>Thu, 15 Oct 2009 16:06:01 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/photo-canvas-tag-flip/#comment-71624</guid>
		<description>Hlo Peter.
Actually you can flip it without diving into imageData  with the Stirfrys way.

    var can = (..), 
        ctx = can.getContext(&#039;2d&#039;), 
        img = new Image();
    img.onload = function(){
            can.width = img.width;
            can.height = img.height;
            ctx.drawImage(img, 0, 0, img.width, img.height);
        }
    img.src = &#039;http://11.media.tumblr.com/tumblr_kr2kxz9bYR1qzklvoo1_500.jpg&#039;;
    can.onclick = function() {
            ctx.scale(-1,1); // to flip vertically, ctx.scale(1,-1);
            ctx.drawImage(can, -img.width, 0, img.width, img.height);    
        }</description>
		<content:encoded><![CDATA[<p>Hlo Peter.<br />
Actually you can flip it without diving into imageData  with the Stirfrys way.</p>
<p>    var can = (..),<br />
        ctx = can.getContext(&#8217;2d&#8217;),<br />
        img = new Image();<br />
    img.onload = function(){<br />
            can.width = img.width;<br />
            can.height = img.height;<br />
            ctx.drawImage(img, 0, 0, img.width, img.height);<br />
        }<br />
    img.src = &#8216;<a href="http://11.media.tumblr.com/tumblr_kr2kxz9bYR1qzklvoo1_500.jpg&#039;" rel="nofollow">http://11.media.tumblr.com/tumblr_kr2kxz9bYR1qzklvoo1_500.jpg&#039;</a>;<br />
    can.onclick = function() {<br />
            ctx.scale(-1,1); // to flip vertically, ctx.scale(1,-1);<br />
            ctx.drawImage(can, -img.width, 0, img.width, img.height);<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Peter</title>
		<link>http://www.phpied.com/photo-canvas-tag-flip/#comment-71331</link>
		<dc:creator>Peter</dc:creator>
		<pubDate>Fri, 21 Aug 2009 09:31:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/photo-canvas-tag-flip/#comment-71331</guid>
		<description>Hi there, nice to see some experimenting with . Just a note: this isn&#039;t an actually flip, this is just rotating the image 180 degrees. Flipping it would require you to get into the imageData.</description>
		<content:encoded><![CDATA[<p>Hi there, nice to see some experimenting with . Just a note: this isn&#8217;t an actually flip, this is just rotating the image 180 degrees. Flipping it would require you to get into the imageData.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stoyan</title>
		<link>http://www.phpied.com/photo-canvas-tag-flip/#comment-71259</link>
		<dc:creator>Stoyan</dc:creator>
		<pubDate>Wed, 29 Jul 2009 04:17:15 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/photo-canvas-tag-flip/#comment-71259</guid>
		<description>Haven&#039;t tried Jacob, but I wouldn&#039;t be surprised.</description>
		<content:encoded><![CDATA[<p>Haven&#8217;t tried Jacob, but I wouldn&#8217;t be surprised.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jacob</title>
		<link>http://www.phpied.com/photo-canvas-tag-flip/#comment-71253</link>
		<dc:creator>Jacob</dc:creator>
		<pubDate>Mon, 27 Jul 2009 20:58:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/photo-canvas-tag-flip/#comment-71253</guid>
		<description>is this possible with video?</description>
		<content:encoded><![CDATA[<p>is this possible with video?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stirfry</title>
		<link>http://www.phpied.com/photo-canvas-tag-flip/#comment-70524</link>
		<dc:creator>Stirfry</dc:creator>
		<pubDate>Sat, 07 Mar 2009 06:43:30 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/photo-canvas-tag-flip/#comment-70524</guid>
		<description>Hey, it bugged me that the code didn&#039;t work each click so I fixed it.


  Flipping photo in a canvas tag
  
    #canvas {cursor: pointer;}
  



    Example of using &lt;code&gt;&lt;canvas&gt;&lt;/code&gt;

    This example shows how a photo is loaded in a &lt;code&gt;&lt;canvas&gt;&lt;/code&gt; tag
    and then flipped.

    Click on the photo to flip (provided, of course, that your browser supports &lt;code&gt;&lt;canvas&gt;&lt;/code&gt;)

    

    
	var can = document.getElementById(&#039;canvas&#039;);
	var ctx = can.getContext(&#039;2d&#039;);
	var drawflip=0
	var img = new Image();
	img.src = &#039;http://www.phpied.com/wp-content/uploads/2008/05/zlati-nathalie.jpg&#039;;

can.onclick = function() {
	can.width = img.width;
	can.height = img.height;

if (drawflip % 2&gt;0){
            ctx.scale(-1,-1)
            ctx.drawImage(img, -img.width, -img.height, img.width, img.height);
		    	}

if (drawflip % 2&lt;=0){
ctx.scale(1,1)
ctx.drawImage(img, 0, 0, img.width, img.height);
			}

drawflip+=1

			};	/*___end can.onclick____*/


    


    &lt;a href=&quot;http://www.phpied.com/photo-canvas-tag-flip/&quot; rel=&quot;nofollow&quot;&gt;Blog post is here&lt;/a&gt;


</description>
		<content:encoded><![CDATA[<p>Hey, it bugged me that the code didn&#8217;t work each click so I fixed it.</p>
<p>  Flipping photo in a canvas tag</p>
<p>    #canvas {cursor: pointer;}</p>
<p>    Example of using <code>&lt;canvas&gt;</code></p>
<p>    This example shows how a photo is loaded in a <code>&lt;canvas&gt;</code> tag<br />
    and then flipped.</p>
<p>    Click on the photo to flip (provided, of course, that your browser supports <code>&lt;canvas&gt;</code>)</p>
<p>	var can = document.getElementById(&#8216;canvas&#8217;);<br />
	var ctx = can.getContext(&#8217;2d&#8217;);<br />
	var drawflip=0<br />
	var img = new Image();<br />
	img.src = &#8216;<a href="http://www.phpied.com/wp-content/uploads/2008/05/zlati-nathalie.jpg&#039;" rel="nofollow">http://www.phpied.com/wp-content/uploads/2008/05/zlati-nathalie.jpg&#039;</a>;</p>
<p>can.onclick = function() {<br />
	can.width = img.width;<br />
	can.height = img.height;</p>
<p>if (drawflip % 2&gt;0){<br />
            ctx.scale(-1,-1)<br />
            ctx.drawImage(img, -img.width, -img.height, img.width, img.height);<br />
		    	}</p>
<p>if (drawflip % 2&lt;=0){<br />
ctx.scale(1,1)<br />
ctx.drawImage(img, 0, 0, img.width, img.height);<br />
			}</p>
<p>drawflip+=1</p>
<p>			};	/*___end can.onclick____*/</p>
<p>    <a href="http://www.phpied.com/photo-canvas-tag-flip/" rel="nofollow">Blog post is here</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Stirfry</title>
		<link>http://www.phpied.com/photo-canvas-tag-flip/#comment-70523</link>
		<dc:creator>Stirfry</dc:creator>
		<pubDate>Sat, 07 Mar 2009 05:53:43 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/photo-canvas-tag-flip/#comment-70523</guid>
		<description>can.onclick = function() {
            ctx.translate(img.width/2, img.height/2);
            ctx.rotate(Math.PI);
            ctx.drawImage(img, -img.width/2, -img.height/2, img.width, img.height);
}
this works without a problem
translate to center of image,rotate, then draw the image offset by how far you translated

but the easiest way is this
flip image down flip it back to the left by scaling -1 -1
now move negative amounts to make up for the scaling
can.onclick = function() {
ctx.scale(-1,-1)
ctx.drawImage(img, -img.width, -img.height, img.width, img.height);
}
try it out</description>
		<content:encoded><![CDATA[<p>can.onclick = function() {<br />
            ctx.translate(img.width/2, img.height/2);<br />
            ctx.rotate(Math.PI);<br />
            ctx.drawImage(img, -img.width/2, -img.height/2, img.width, img.height);<br />
}<br />
this works without a problem<br />
translate to center of image,rotate, then draw the image offset by how far you translated</p>
<p>but the easiest way is this<br />
flip image down flip it back to the left by scaling -1 -1<br />
now move negative amounts to make up for the scaling<br />
can.onclick = function() {<br />
ctx.scale(-1,-1)<br />
ctx.drawImage(img, -img.width, -img.height, img.width, img.height);<br />
}<br />
try it out</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: photo canvas guy</title>
		<link>http://www.phpied.com/photo-canvas-tag-flip/#comment-69892</link>
		<dc:creator>photo canvas guy</dc:creator>
		<pubDate>Fri, 26 Sep 2008 16:44:54 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/photo-canvas-tag-flip/#comment-69892</guid>
		<description>thanks for posting this rotation method, the pixel correction is throwing me off too- but glad someone more technical than myself can share this, thanks again.

Stephen.</description>
		<content:encoded><![CDATA[<p>thanks for posting this rotation method, the pixel correction is throwing me off too- but glad someone more technical than myself can share this, thanks again.</p>
<p>Stephen.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Louis</title>
		<link>http://www.phpied.com/photo-canvas-tag-flip/#comment-69486</link>
		<dc:creator>Louis</dc:creator>
		<pubDate>Thu, 26 Jun 2008 22:03:14 +0000</pubDate>
		<guid isPermaLink="false">http://www.phpied.com/photo-canvas-tag-flip/#comment-69486</guid>
		<description>Clean, lightweight, but I don&#039;t think it&#039;s the good approch.

By wrapping the image inside a &lt;code&gt;&lt;/code&gt; element, you lose all the browser UI for the image. You can drag &amp; drop it, you can&#039;t open it in another tab, etc. Also, from a semantic point of view, it&#039;s an obscur method : search engines won&#039;t be very glad to find a &lt;code&gt;&lt;/code&gt; tag.

I think image manipulations belongs to CSS, and we may see them very soon with the implementation of CSS 3 recommendations in Webkit and Firefox.</description>
		<content:encoded><![CDATA[<p>Clean, lightweight, but I don&#8217;t think it&#8217;s the good approch.</p>
<p>By wrapping the image inside a <code></code> element, you lose all the browser UI for the image. You can drag &amp; drop it, you can&#8217;t open it in another tab, etc. Also, from a semantic point of view, it&#8217;s an obscur method : search engines won&#8217;t be very glad to find a <code></code> tag.</p>
<p>I think image manipulations belongs to CSS, and we may see them very soon with the implementation of CSS 3 recommendations in Webkit and Firefox.</p>
]]></content:encoded>
	</item>
</channel>
</rss>

