You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
2.3 KiB

  1. # DarkroomJS
  2. DarkroomJS is a JavaScript library which provides basic image editing tools in
  3. your browser, such as **rotation** or **cropping**. It is based on the awesome
  4. [FabricJS](http://fabricjs.com/) library to handle images in HTML5 canvas.
  5. ## Demo
  6. Try the online demo at [http://mattketmo.github.io/darkroomjs](http://mattketmo.github.io/darkroomjs/)
  7. The library is currently *work in progress*.
  8. I know there is some bug especially when resizing the crop zone.
  9. Feel free to fork the project or report issues on GitHub.
  10. All ideas are also welcome.
  11. ## Building
  12. - Install [Node](http://nodejs.org/) & `npm`.
  13. - Run `npm install` to build dependencies.
  14. - Run `npm start` to build the assets and start the demo webserver.
  15. ## Usage
  16. Simply instanciate a new Darkroom object with a reference to the image element:
  17. ```html
  18. <img src="some-image.jpg" id="target">
  19. <script>
  20. new Darkroom('#target');
  21. </script>
  22. ```
  23. You can also pass some options:
  24. ```javascript
  25. new Darkroom('#target', {
  26. // Canvas initialization size
  27. minWidth: 100,
  28. minHeight: 100,
  29. maxWidth: 500,
  30. maxHeight: 500,
  31. // Plugins options
  32. plugins: {
  33. crop: {
  34. minHeight: 50,
  35. minWidth: 50,
  36. ratio: 1
  37. },
  38. save: false // disable plugin
  39. },
  40. // Post initialization method
  41. initialize: function() {
  42. // Active crop selection
  43. this.plugins['crop'].requireFocus();
  44. // Add custom listener
  45. this.addEventListener('core:transformation', function() { /* ... */ });
  46. }
  47. });
  48. ```
  49. ## Why?
  50. It's easy to get a javascript script to crop an image in a web page.
  51. But if your want more features like rotation or brightness adjustment, then you
  52. will have to do it yourself. No more jQuery plugins here.
  53. It only uses the power of HTML5 canvas to make what ever you want with your image.
  54. ## The concept
  55. The library is designed to be easily extendable. The core script only transforms
  56. the target image to a canvas with a FabricJS instance, and creates an empty toolbar.
  57. All the features are then implemented in separate plugins.
  58. Each plugin is responsible for creating its own functionality.
  59. Buttons can easily be added to the toolbar and binded with those features.
  60. ## Contributing
  61. Run `npm develop` to build and watch the files while developing.
  62. ## License
  63. DarkroomJS is released under the MIT License. See the [bundled LICENSE file](LICENSE)
  64. for details.