-
Notifications
You must be signed in to change notification settings - Fork 405
How to use
The files with 'full' in the URL include both the core library and all of the CamanJS plugins. The files without 'full' in the URL only include the core library, and plugins must be included separately if you wish to use them.
The 'min' files are the minified versions of each.
Using CamanJS is simple. It goes something like this:Caman('path/to/image.jpg', '#canvas-id', function () {
this.brightness(10);
this.contrast(-5);
this.saturation(-50);
// and so on...
this.render();
});
You can also directly point to an image if you don't want to create a separate canvas element. In this case, the image element will be replaced with the canvas element, and the canvas will be drawn with the image content:
Caman("#image-id", function () {
this.contrast(-5).render();
});
The canvas can be resized using the HTML5 data attributes data-camanwidth and/or data-camanheight, like this:
<img src="testimg.jpg" data-camanwidth="300" data-camanheight="150" />
Both the width and height are optional. If only one is given, the canvas will be resized proportionally.
If you are already using a popular JS library on your site (such as jQuery, Mootools, ExtJS, etc), then there may be an adapter for CamanJS that integrates it with that library. Remember, CamanJS is fully standalone and isn't dependent on any library, but the option is there if you like a more tightly integrated environment.All adapters are located in the adapters/ folder. Simply include them after you include CamanJS.
<script type="text/javascript" src="caman.full.min.js"></script>
<script type="text/javascript" src="adapters/jquery.js"></script>
<script type="text/javascript">
$("#caman-image").caman(function() {
this.brightness(10).render();
});
</script>
Caman('img/example.jpg', '#image-caman', function () {
this.saturation(-20);
this.brightness(10);
this.render(function () {
this.save('png'); // shows a download file prompt
// or...
this.toBase64(); // base64 data URL representation of the image. useful if you want to upload the modified image.
});
});
Caman('#test', function () {
this.brightness(10);
/*
* Creates a new layer. Everything called inside the callback argument will be applied
* to the new layer. Layers have some special layer-only functions such as setBlendingMode(),
* opacity(), and copyParent(). In order to access the standard filters, you need to access them
* through this.filter.
*/
this.newLayer(function () {
// There are many blending modes, more below.
this.setBlendingMode('multiply');
this.opacity(10);
this.copyParent();
this.filter.gamma(0.8);
this.filter.contrast(50);
/*
* Yep, you can stack multiple layers! The further a layer is nested, the higher up on the layer
* stack it will be.
*/
this.newLayer(function () {
this.setBlendingMode('softLight');
this.opacity(10);
this.fillColor('#f49600');
});
this.filter.exposure(10);
});
this.exposure(20);
this.gamma(0.8);
this.render();
});
- normal
- multiply
- screen
- overlay
- difference
- addition
- exclusion
- softLight
Caman("#test", function () {
this.contrast(5);
this.newLayer(function () {
this.setBlendingMode('softLight');
this.opacity(20);
this.overlayImage('images/overlay.jpg');
});
this.render();
});
CamanJS comes with a PHP proxy (you're welcome to add a proxy in the language of your choice) that you can use in the proxies folder. Before you use CamanJS for editing, all you have to do to enable the proxy is:
// Will use the PHP proxy in the proxies folder.
Caman.remoteProxy = Caman.IO.useProxy('php');
// You can also specify a URL instead of calling useProxy().
// This will call /proxies/proxy.php?camanProxyUrl={url}
Caman.remoteProxy = "/proxies/proxy.php";
If no proxy is defined when a remote image is attempted to be edited, an error will be thrown.