Rotate a Photo on Canvas Using HTML 5

Introduction

This is a simple application for beginners that help show how to rotate a photo on canvas using HTML 5 and CSS tools. We know that HTML 5 is the advanced version of HTML. Basically HTML 5 can be used to develop 3D applications. This article is intended to help with the use of HTML5 tools to develop a photo on canvas application. CSS is the acronym for Cascading Style Sheet that is used for design. CSS defines how HTML elements are to be displayed. Canvas is an important tag of a HTML 5 that is used to show the image and text in a HTML 5 application. I hope this article helps to show how to rotate a photo on canvas using HTML 5 and CSS tools.

Step 1 : First Open a HTML editor such as Notepad.

  • Open start->Notepad.
  • The name of editor is "canvas".

notepad.gif

Step 2 :
Create a Folder on a desktop.

  • Right-click on desktop->new->Folder.
  • Name of folder is "photo".

folder.gif

Step 3 :
Open Visual Studio.

  • Go to file -> New->Projects.
  • Crete an ASP. NET Web Application.
  • Name of "Tom.aspx".

new application.gif

openapplication.gif

Step 4 :
Add a HTML file to your web application.

  • Right-click on Solution Explorer.
  • Add->add new item->HTML form.
  • The Name of the HTML form is "Image.html".

html.gif

Step 5 :
Add a image folder on a Tom canvas application.

  • Right click of Solution explorer.
  • add->add folder.
  • Name of folder is "image".

image.gif

Step 6 :
Add a some js file in a application.

Code

<script src="Scripts/canvas.js" type="text/javascript"></script>
<
script src="Scripts/canvas2.js" type="text/javascript"></script>

Step 7 : Now we have set a style of canvas curser properties that are background color, fontsize, height, width and also set a properties of an image field.

Code

<style type="text/css" media="screen">
  can.resize-ne { cursor: ne-resize; }
  can.resize-se { cursor: se-resize; }
  can.resize-sw { cursor: sw-resize; }
  can.resize-nw { cursor: nw-resize; }
  can.move { cursor: move; }
  can.default { cursor: default; }
  img    { display: block; visibility: hidden; position: absolute; top: -1000; left: -1000; }
  input { margin-left: 20px; }
  fieldset { width: 480px; float: left; }
 .fieldset { width: 400px; float: left; }
  #ft    { background-color: #eee; height: 70px; width: 99%;top: 0; left: 0; }
             #ft span { width: 100%; }
</style>

Step 8 : In this step set a canvas length and add an image according to image id.

Code

can = new Canvas.Element();
 can.init('canvid1', { width: rex.getViewportWidth() - 5, height: rex.getViewportHeight() - 5 });
 img[img.length] = new Canvas.Img('img1', {});
 img[img.length] = new Canvas.Img('img2', {});
 img[img.length] = new Canvas.Img('img3', {});
 img[img.length] = new Canvas.Img('img4', {});
 img[img.length] = new Canvas.Img('img4', {});
 can.addImage(img[0]);
 can.addImage(img[1]);
 can.addImage(img[2]);
 can.setCanvasBackground(img[3]);
 can.addImage(img[4]);
 this.initEvents();
}

Step 9 : Now set the click event of set, erase and cover checkbox; after click they all of perform an action.

Code  

initEvents: function ()
{
  ctx.on('togglebg', 'click', this.toggleBg, this, true);
  ctx.on('S1', 'click', this.S1, this, true);
  ctx.on('T1', 'click', this.T1, this, true);
  ctx.on('T3', 'click', this.T3, this, true);
  ctx.on('T2', 'click', this.T2, this, true);
 }

Step 10 :  Now in this step set a body of canvas web page.

body.gif

Code

<body id="canvasdemo" onload="" bgcolor="#ffccff">  
    <canvas id="canvid1" ></canvas>
   <img id="img4" src="image/1.jpg" />
   <img id="img1" src="image/2.jpg" />
   <img id="img2" src="image/6.jpg" />
   <img id="img3" src="image/7.jpg" />
   <div id="ft">
   <div class="fieldset">
   &nbsp;
  </div>
  <fieldset>
     <legend style="background-color: #008080">Image</legend>
     <span style="background-color: #FF9999"><input type="checkbox" name="some_name" value="" id="T1" />Erase</span>
     <span style="background-color: #99FF99"><input type="checkbox" name="some_name"
        value="" id="T3" style="background-color: #FFCCFF" />Cover</span>
      <span style="background-color: #99FFCC"><input type="checkbox" name="some_name" value="" id="T2" />Set</span>
   </fieldset>
       <span style="background-color: #FF99FF"><input type="checkbox" name="some_name" value="" id="S1" /> Cover show<span>
  </div>
</body>

Step 11 : Press Ctrl + F5 to run the application in a browser.

Output

 1.gif

 2.gif

 3.gif

 4.gif

Resources

Here is some useful resource :

Up Next
    Ebook Download
    View all
    Learn
    View all