
Research
Malicious npm Packages Impersonate Flashbots SDKs, Targeting Ethereum Wallet Credentials
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Allow users to crop images within an area (fully responsive). Supports dragging (touch support), zoom and rotation.
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.
(2.7kb minified and gzipped)
Load the required files:
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.
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.
Bind actions:
$('#rotate-left-button').click(function(){
picture.guillotine('rotateLeft');
});
$('#zoom-in-button').click(function(){
picture.guillotine('zoomIn');
});
...
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/rot')eLeft/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...
}
});
Enjoy!
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.
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).
Guillotine is dual licensed under the MIT or GPLv3 licenses.
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.
See CONTRIBUTING.md
FAQs
Allow users to crop images within an area (fully responsive). Supports dragging (touch support), zoom and rotation.
The npm package guillotine receives a total of 411 weekly downloads. As such, guillotine popularity was classified as not popular.
We found that guillotine demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Four npm packages disguised as cryptographic tools steal developer credentials and send them to attacker-controlled Telegram infrastructure.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.