Setup Tasks:

1. Upload yesterday's web page to your designcodebuild.com website.
2. Download & setup camanjs library
3. Include all the js and css files in the HTML file.

Let's get started:

Download camanjs from camanjs.com
  • Unzip it
  • Copy [camanfolder]/dist/caman.full.js to the base folder.
  • Include the necessary .js and library files in your HTML page by adding these lines inside <head></head>:

<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.4.min.js"></script> 
<script type="text/javascript" src="caman/caman.full.min.js"></script>
<script type="text/javascript" src="basicCaman.js"></script>

We should now allow the user to add preset filters to their image. This will primarily require html and javascript.

Start by creating buttons for the filters you want. We will position them later.

Now, enable the buttons using javascript and jQuery. Use this at the beginning of the <script>: javascript var camanObject = Caman("#toEdit");

Where #toEdit is the id of the image.

Now, create this: javascript $( document ).ready(function() { }

Within this "document.ready" section, we can make the buttons respond when clicked on. Add this code within $( document ).ready, which will make the "vintage" button work. javascript $(" #vintage ").on("click", function(){ camanObject.revert(false); camanObject["vintage"](); camanObject.render(); }); // ...

The most important part of this code is the middle line, "camanObject'vintage';". This applies the actual filter, vintage, to the image. However, that code will change the image currently displayed. What if the user had already applied a different filter? Then it would effectively apply two filters. Instead, we need to return back to how the image originally looked.

This line - "camanObject.revert(false);" - does that. By specifying "false", we ask camanjs not to render immediately after reverting, because that would take extra time.

Finally, "camanObject.render()" makes changes to the image visible to the user.

Note that if the filter is two words -- like "Cross Product" -- we must use camelCase. Instead of writing camanObject["cross product"], camanJS will instead react to camanObject["crossProduct"].

There are two more functions we need: revert and submit. Add both of these buttons: html The back button is easy to make work. javascript $( "#back" ).on("click", function(){ camanObject.revert(true); }); However, the submit button will be a bit more difficult. Remember, we need to go to the next page to further edit the image. We will therefore need to send some data about the image. Specifically, where the image is stored, the type of image, and the actual image data. We have multiple options: 1. Send an AJAX request 2. Save the image, and then proceed while giving the next page the file name 3. Send all required data through a post form request. We cannot send an AJAX request because it will not redirect to the new page. CamanJS also does not allow for saving the image (to my knowledge), so this leaves us with option 3. This is most easily achieved by creating a form. ```php

``` When this form is submitted, it will send this info to the next page (third.php) Look at ce_escape_string($filename). This is a function defined in basicCaman.php. Feel free to look there; this function just escapes all potentially dangerous characters, like slashes. These characters can interrupt data transmission through a post request.

Now, we must fill in the imageData input. Since we hope to send an updated image that was just processed by Camanjs, we should work on a javascript function. javascript $( "#submit" ).on("click", function(){ var imageData = camanObject.toBase64(); imageData = ceEscapeString(imageData); // escape this string, too. $( "#imageData" ).val(imageData); $( "#dataForm" ).submit(); });

CamanJS provides us with a function to export the image data to a base64 encoding. Now, escape the string to avoid bad characters. We then input that data into the form (so that it will be sent) and then submit the form.