All Projects → matiasgali → guillotine

matiasgali / guillotine

Licence: other
jQuery plugin to crop images within an area (fully responsive), allowing to drag (touch support), zoom and rotate.

Programming Languages

coffeescript
4710 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to guillotine

Sidr
Sidr is a jQuery plugin for creating side menus and the easiest way for doing your menu responsive.
Stars: ✭ 2,924 (+810.9%)
Mutual labels:  jquery-plugin, responsive
Guillotine
jQuery plugin to crop images within an area (fully responsive), allowing to drag (touch support), zoom and rotate.
Stars: ✭ 318 (-0.93%)
Mutual labels:  jquery-plugin, responsive
ml-stack-nav
Customizable, responsive, accessible, easy-to-use multi-level stack navigation menu with slide effect.
Stars: ✭ 20 (-93.77%)
Mutual labels:  jquery-plugin, responsive
xGallerify
A lightweight, responsive, smart gallery based on jQuery
Stars: ✭ 52 (-83.8%)
Mutual labels:  jquery-plugin, responsive
Imgnotes
Extension of the jQuery imgViewer plugin to add markers and notes to the image
Stars: ✭ 98 (-69.47%)
Mutual labels:  jquery-plugin, responsive
Jquery.sumoselect
A jQuery Single/Multi Select plugin which can be used on almost any device
Stars: ✭ 527 (+64.17%)
Mutual labels:  jquery-plugin, responsive
Stickystack.js
A jQuery plugin that creates a stacking effect by sticking panels as they reach the top of the viewport.
Stars: ✭ 287 (-10.59%)
Mutual labels:  jquery-plugin, responsive
Restable
jQuery plugin that makes tables responsive converting them to HTML lists on small viewports.
Stars: ✭ 183 (-42.99%)
Mutual labels:  jquery-plugin, responsive
Jquery Calendar
A responsive jquery calendar scheduler built with bootstrap and moment.js
Stars: ✭ 67 (-79.13%)
Mutual labels:  jquery-plugin, responsive
Imgviewer
jQuery plugin to zoom and pan images, even those with a size that is a percentage of their container
Stars: ✭ 50 (-84.42%)
Mutual labels:  jquery-plugin, responsive
Jquery Rwdimagemaps
Responsive Image Maps jQuery Plugin
Stars: ✭ 1,511 (+370.72%)
Mutual labels:  jquery-plugin, responsive
scalem
A jQuery plugin to make any element scalable (responsive).
Stars: ✭ 33 (-89.72%)
Mutual labels:  jquery-plugin, responsive
jquery-custom-select
Custom Select jQuery Plugin
Stars: ✭ 27 (-91.59%)
Mutual labels:  jquery-plugin
svelte-grid-responsive
Responsive grid system based on Bootstrap for Svelte
Stars: ✭ 41 (-87.23%)
Mutual labels:  responsive
cazary
jQuery plugin of WYSIWYG editor that aims for fast, lightweight, stylish, customizable, cross-browser, and multi-language.
Stars: ✭ 12 (-96.26%)
Mutual labels:  jquery-plugin
jquery-slidescrollpanel
Create sliding scroll panels that slide in by touch, trackpad and scrolling
Stars: ✭ 16 (-95.02%)
Mutual labels:  jquery-plugin
jquery-particles-burst
Lightweight particles generator
Stars: ✭ 21 (-93.46%)
Mutual labels:  jquery-plugin
responsive-native
A responsive utility toolkit for React Native 📱⚛
Stars: ✭ 331 (+3.12%)
Mutual labels:  responsive
kolorwheel.js
🌈 Color palette generator JavaScript library
Stars: ✭ 37 (-88.47%)
Mutual labels:  jquery-plugin
jquery-profile
jQuery plugin to profile calls to jQuery selectors.
Stars: ✭ 39 (-87.85%)
Mutual labels:  jquery-plugin

jQuery Guillotine Plugin

NPM

Demo

http://guillotine.js.org

Description

Guillotine is a jQuery plugin that allows to drag, zoom or rotate an image to select a cropping area. Like selecting the display area of a profile picture or avatar.

  • Responsive: The window (or selection area) is fully responsive (fluid).
  • Touch support: Dragging the image also works on touch devices.

(2.7kb minified and gzipped)

Setup

  1. Load the required files:

    • jquery.js
    • jquery.guillotine.js
    • jquery.guillotine.css
  2. Set the width of the parent element:

    <div id="theparent" style="width: 80%;">
      <img id="thepicture" src="url/to/image">
    </div>

    The window ("the guillotine") that will wrap around the image when the plugin is instantiated is fully responsive (fluid) so it will always take all the width left by its parent.

  3. Instantiate the plugin:

    var picture = $('#thepicture');  // Must be already loaded or cached!
    picture.guillotine({width: 400, height: 300});

    Here we set the dimensions we want for the cropped image (400x300), which are totally independent of the size in which the "guillotine" or "window" is actually displayed on screen.

    Even though it's responsive, the data returned always corresponds to the predefined dimensions. In this case, it will always get a cropped image of 400 by 300 pixels.

    Notice: Make sure that the target element is ready before instantiating!

    If it's an image, make sure that it is already loaded or cached before calling Guillotine, so it can get its dimensions and display it properly. You can use the onload event, the complete property or check that the image has a width greater than zero to determine if it's loaded.

  4. Bind actions:

    $('#rotate-left-button').click(function(){
      picture.guillotine('rotateLeft');
    });
    
    $('#zoom-in-button').click(function(){
      picture.guillotine('zoomIn');
    });
    
    ...
  5. Handle cropping instructions:

    The plugin is not meant to actually crop images but to generate the necessary instructions to do so on the server.

    • You can get the instructions at any point by calling 'getData':

      data = picture.guillotine('getData');
      // { scale: 1.4, angle: 270, x: 10, y: 20, w: 400, h: 300 }

      Important: You should rotate and scale first, and then apply the cropping coordinates to get it right!

    • Or you can use a callback or a custom event to listen for changes:

      var otherPicture = $('#other-picture');
      otherPicture.guillotine({eventOnChange: 'guillotinechange'});
      otherPicture.on('guillotinechange', function(ev, data, action){
        // this = current element
        // ev = event object
        // data = { scale: 1.4, angle: 270, x: 10, y: 20, w: 400, h: 300 }
        // action = drag/rotateLeft/rotateRight/center/fit/zoomIn/zoomOut
        // Save data on hidden inputs...
      });

      Set the 'onChange' option instead if you prefer to use a callback:

      otherPicture.guillotine({
        onChange: function(data, action){
          // Do something...
        }
      });
  6. Enjoy!

API

Once instantiated, you can interact with the plugin by passing instructions as strings. Here is the complete public API:

// Transformations
// rotateLeft, rotateRight, center, fit, zoomIn, zoomOut
picture.guillotine('zoomOut');
picture.guillotine('rotateRight');
...

// Get current data
// { scale: 1.4, angle: 270, x: 10, y: 20, w: 400, h: 300 }
var data = picture.guillotine('getData');

// Get instance (Guillotine instance)
var guillotine = picture.guillotine('instance');

// Disable/Enable the plugin
picture.guillotine('disable');
picture.guillotine('enable');

// Remove the plugin (reset everything)
picture.guillotine('remove');

Optionally, you can set the initial position and state of the image with the init option. It takes a data object similar to the one returned by getData. You may set angle, scale, x and y, any other property will be ignored:

picture.guillotine({
  width: 400,
  height: 300,
  init: { angle: 90, x: 80 }
});

For further info and options dig through the [code base] (src/jquery.guillotine.coffee) that has a fair share of comments and it's intentionally coded in CoffeScript to ease out reading and customizing it.

Support

  • Dragging support for both mouse and touch devices (works on IE8).
  • Rotation is achieved using CSS3 'transform' property, so it doesn't work on IE8, but it's automatically disabled on devices that don't support it. In such case rotateLeft and rotateRight won't perform any action but will still trigger the event and/or callback to let you know the user is trying and allow you to handle it appropriately.
  • Zoom, Fit and Center are handled with absolute positioning, they work on IE8.

For a more detailed list of supported browsers and devises check out the support page on the wiki.

It would be great if you could test it on other browsers and devices and share your experience on the wiki (or open an issue if it doesn't work properly).

License

Guillotine is dual licensed under the MIT or GPLv3 licenses.

More features

The plugin aims to have a simple and general API to allow interaction, specific features and the user interface are left for the developer to implement. This allows the plugin to be as flexible as possible.

For edge cases is that the code base has been kept as maintainable as possible, in those cases you are free and encouraged to customize the plugin to suite your needs.

Contributing

See CONTRIBUTING.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].