简体   繁体   中英

How to Rotate Canvas using CamanJS?

I use Caman.js and hava a

<canvas> 

element on my page.

How can I rotate this canvas with Caman.js?

I found this but I do not know how to apply it.

Use this:

Caman("#canvasId", function () {
  this.rotate(90);
  this.render();
});

Rotate is a Plugin.
You have to compile Caman.js with the plugin since its all written in coffeescript .

The plugins you will find here: https://github.com/meltingice/CamanJS-Plugins

For how to include them have a look at the cakefile

After that is done it will work as stephan1001 wrote.

To outline in more detail on how to get the rotate plugin (and other plugins for Camanjs) included in Camanjs I followed these steps:

  1. Download the plugin files (.coffee files) from camanjs plugin github
  2. Install coffee script through npm. npm install -g coffee-script
  3. Compile the plugin with coffee -c /path/to/script.coffee
  4. Now you will have a .js file. Delete the surronding immediatly invoking function as you will not want it when you place it in the caman.js file (or caman.full.js like I did).
  5. Take the code from the plugin (with the surronding function removed) and paste it at the bottom of you caman.js file, but above the last closing brace.

Now you will have the plugin included into your caman plugin.

Note: I'm sure there is a better way to do this, however, this worked for me and I couldn't find any other information out there outlining these steps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM