Giter VIP home page Giter VIP logo

srcissors's Introduction

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.

srcissors's People

Contributors

caillou avatar dependabot[bot] avatar gabrielhase avatar manufaktor avatar marcbachmann avatar peyerluk avatar renovate[bot] avatar romankaravia avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

srcissors's Issues

Add a crop.setImage() method

It would be nice to be able to exchange the image in Srcissors.

Currently, when I call crop.preview.setImage() Srcissors stops zooming.

Nice to have: reset the zoom level.

Action Required: Fix Renovate Configuration

There is an error with this repository's Renovate configuration that needs to be fixed. As a precaution, Renovate will stop PRs until it is resolved.

Error type: Cannot find preset's package (local>livingdocsIO/renovate-config)

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

npm
package.json
  • @babel/core ^7.21.4
  • @babel/preset-env ^7.21.4
  • babel-loader ^9.1.2
  • chai ^4.3.7
  • electron ^30.0.0
  • karma ^6.4.2
  • karma-chai ^0.1.0
  • karma-chrome-launcher ^3.2.0
  • karma-electron ^7.3.0
  • karma-firefox-launcher ^2.1.2
  • karma-mocha ^2.0.1
  • karma-safari-launcher ^1.0.0
  • karma-sinon-chai ^2.0.2
  • karma-webpack ^5.0.0
  • mocha ^10.2.0
  • sinon ^18.0.0
  • sinon-chai ^3.7.0
  • webpack ^5.80.0
  • webpack-cli ^5.0.2
  • webpack-dev-server ^5.0.0
  • jquery ^3.6.4
  • node >=6

  • Check this box to trigger a request for Renovate to run again on this repository

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.