Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

srcissors

Package Overview
Dependencies
Maintainers
4
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

srcissors

Image cropping for responsive images

  • 2.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
4
Created
Source

srcissors

Image cropping for responsive images. (~5kB minified and gzipped)

Js

// Initialize srcissors
var cropper = srcissors.new({
  arena: $('.crop-arena'),
  url: "/images/diagonal.jpg",
  fixedWidth: 300,
  minRatio: 1/1.5,
  maxRatio: 1.5/1
});

// Set a crop
cropper.setCrop({
  x: 1096,
  y: 461,
  width: 700,
  height: 500
})

// Get the current crop
cropper.getCrop();

// Set a ratio
cropper.setRatio(4/3);

// Reset to show the full image without any crop applied
cropper.reset();

// Set a new url
cropper.setImage('/images/storytelling-painting.jpg');

// Listen for the ready event (only fired once)
cropper.on('ready', function() {
    // your code
});

// Listen for image load events
cropper.on('load', function() {
    // your code
});

cropper.on('change', function(crop) {
    var x, y, width, height;
    x = crop.x;
    y = crop.y;
    width = crop.width;
    height = crop.height;
});


Configuration Options

ParameterType
arenajQuery element
urlStringUrl of the image to load
cropObject{x, y, width, height} Initial crop. The same as calling setCrop()
minResolutionThe minimal resolution required from the resulting image.
fixedWidth, fixedHeightNumberWill fix the preview width and only allow for resizes in the other axis.
minWidth, minHeightNumberMinimum width or height the preview can be.
minRatio, maxRatioNumberProhibit extreme image ratios with these settings.
maxAreaNumbere.g. 0.8 means max 80% of the area will be covered by the image. This makes for smoth transitions between wide and tall image formats.
zoomStepNumbere.g. 1.25 means every zoom will enlarge the preview by 25%.
actionsObject{pan, zoomOnDoubleClick, resize } Allowed user interactions. By default they are all set to true.
showSurroundingImageString{always, never, panning } Shows the uncropped part of the image. By default set to never.
surroundingImageOpacityNumber{0.0 - 1.0} Sets the opacity when showing the uncropped part of the image. By default set to 0.2.
originalSizeObjectOriginal image size, can be used to display a downscaled version of the image in the cropping interface, but use the original size for crop attributes; e.g. {width: 4000, height: 3000}.

HTML

This is the basic HTML used by srcissors in the examples. The zoom controls are not needed by the script and you need create the click events for zooming yourself. Have a look at how it can be done in examples/index.html.

There are also more setups for you to look at in examples/fit-to-area.html and examples/small-image.html.

<div class="crop-arena">
  <div class="crop-view">
    <!-- Outline -->
    <div class="crop-outline"></div>

    <!-- zoom controls -->
    <div class="top-left">
        <div class="crop-zoom-controls crop-zoom-controls--outside">
          <a class="icon-zoom icon-zoom-in" href="#" title="Zoom in"></a>
          <a class="icon-zoom icon-zoom-out" href="#" title="Zoom out"></a>
        </div>
    </div>

    <!-- image -->
    <div class="crop-preview clip-content cover-all"></div>

  </div>
</div>

Css

All the UI elements are styled with CSS. Just start with the CSS from examples/css/srcissors.css.

Development

# Watch for changes and fire up a webserver with livereload
npm run start

# Run the tests with karma
npm run test

# Run the tests in the major browsers (Chrome,Firefox,Safari,Electron)
npm run test:browsers

# Run tests and build scrissors.js and scrissors.min.js
npm run build

# Publish the module to npm
npm run build && npm version minor && git push && npm publish



Licence

Copyright (c) 2015 upfront GmbH

This program is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License (LGPL) as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

Keywords

FAQs

Package last updated on 11 May 2023

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc