npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

srcissors

v2.1.4

Published

Image cropping for responsive images

Downloads

2,531

Readme

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

| Parameter | Type | | |---------------|-------------|--------------------------------| | arena | jQuery element | | | url | String | Url of the image to load | | crop | Object | {x, y, width, height} Initial crop. The same as calling setCrop() | | minResolution | The minimal resolution required from the resulting image. | | fixedWidth, fixedHeight | Number | Will fix the preview width and only allow for resizes in the other axis. | | minWidth, minHeight | Number | Minimum width or height the preview can be. | | minRatio, maxRatio | Number | Prohibit extreme image ratios with these settings. | | maxArea | Number | e.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. | | zoomStep | Number | e.g. 1.25 means every zoom will enlarge the preview by 25%. | | actions | Object | {pan, zoomOnDoubleClick, resize } Allowed user interactions. By default they are all set to true. | | showSurroundingImage | String | {always, never, panning } Shows the uncropped part of the image. By default set to never. | | surroundingImageOpacity | Number | {0.0 - 1.0} Sets the opacity when showing the uncropped part of the image. By default set to 0.2. | | originalSize | Object | Original 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.