GithubHelp home page GithubHelp logo

simonwaldherrarchive / camanjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from meltingice/camanjs

1.0 2.0 0.0 4.58 MB

Pure Javascript HTML5 (Ca)nvas (Man)ipulation

Home Page: http://camanjs.com

License: BSD 3-Clause "New" or "Revised" License

camanjs's Introduction

About the Project

The main focus of CamanJS is manipulating images using the HTML5 canvas and Javascript. It's a combination of a simple-to-use interface with advanced and efficient image/canvas editing techniques. It is also completely library independent and can be safely used next to jQuery, YUI, Scriptaculous, MooTools, etc.

CamanJS is very easy to extend with new filters and plugins, and it comes with a wide array of image editing functionality, which is only growing as the community makes more plugins.

For more information, I highly recommend taking a look at the official website where there is more comprehensive documentation and interactive demos. You can also read the wiki for some basic information about the project and how to use it.

CamanJS is written in Coffeescript as of version 3.0. It works both in-browser and in NodeJS.

Example Usage

Include one of the versions in the dist/ folder, then you can run:

Caman("#image-id", function () {
  this.brightness(10);
  this.contrast(20);
  this.render(function () {
    alert("Done!");
  });
});

Caman also supports modifying images via the data-caman HTML attribute. Simply separate each instruction with a space. Images with the data-caman attribute will automatically be modified at page load.

<img data-caman="saturation(-10) brightness(20) vignette('10%')" src="path/to/image.jpg">

Upgrading from 2.x to 3.x

For the end-user, there are no changes to CamanJS that will affect your code. Everything works exactly the same as before.

For developers, there are some major changes regarding how filters and plugins are added to CamanJS. Previously, you would explicitly extend the Caman.manip interface. This object no longer exists. Now, the way you add filters is:

Caman.Filter.register "filterName", ->
  # Variables that exist here will be available in the process function
  # because of JS closure.
  amt = 20

  @process "filterName", (rgba) ->
    # Alter rgba pixel object here
    return rgba

Plugins are similarly added:

Caman.Plugin.register "pluginName", ->
  return @

Building CamanJS

If you are a developer who is contributing directly to the project, there are some tools to help you out.

The requirements for building CamanJS are:

  • node
  • coffeescript
  • jsmin (for node)

If you're running OSX and have Growl installed, it's also recommended you have:

  • coffeescript-growl

To build, simply run:

cake build

The resulting files will be placed in the dist/ folder. Plugins will be automatically discovered and added to caman.full.js after the core library.

If you add any files to the core library, you will need to add them to the coffeeFiles array in the Cakefile. The point of this is so that order is preserved when generating the file JS file. Plugins do not need to be added to the Cakefile.

You will probably want to generate documentation if you make any changes or add a plugin. In addition to the normal requirements, you will also need:

  • docco
  • Pygments (Python library)

To generate the documentation, run:

cake docs

CDN JS Hosting

CamanJS is hosted on CDN JS if you're looking for a CDN hosting solution. It is the full and minified version of the library, which means all plugins are included. Simply load CamanJS directly from this URL for usage on your site.

NodeJS Compatibility

CamanJS is fully compatible with NodeJS. The easiest way to install and use it is:

npm install caman -g

If you wish to do things a bit manually, the required libraries are:

  • cairo >= 1.10.0
  • libjpeg
  • libpng
  • node-canvas
    • Can also use: npm install canvas -g

Saving from NodeJS

To save your modified image in NodeJS, simply call the save() function after rendering is finished by passing a callback function to render(). Trying to save before rendering is finished will cause issues.

Caman "./path/to/file.jpg", ->
  @brightness 40
  @render -> @save "./output.jpg"

Testing

CamanJS has both QUnit unit testing and a custom benchmarking page to monitor render times on a per-filter basis. Simply open test/index.html for the QUnit tests, and test/benchmark.html for the benchmarking tests.

Project Contributors

Plugin Contributors

camanjs's People

Contributors

meltingice avatar rwaldron avatar cezarsa avatar bebraw avatar mihelich avatar robertlong avatar sigbjornf avatar yannickcr avatar

Stargazers

Simon Waldherr avatar

Watchers

Simon Waldherr avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.