GithubHelp home page GithubHelp logo

infomaker / cropjs Goto Github PK

View Code? Open in Web Editor NEW
4.0 16.0 2.0 12.88 MB

Image soft crop tool including trackingjs for automatic cropping

License: MIT License

JavaScript 89.51% CSS 0.85% HTML 4.94% Shell 0.05% SCSS 4.65%

cropjs's Introduction

CropJS

About CropJS

CropJS is a lightweight soft crop tool for to integration into other projects. It uses TrackingJS to enable automatic feature and face detection based cropping for a preset number of predefined crop dimensions.

Usage

Installation

npm install @infomaker/cropjs

Define a placeholder for the crop dialog

<div id="crop_impl"></div>

Instantiate a new crop dialog

// Get div where cropjs is loaded
var div = document.getElementById('crop_impl');

// Get access to the editor object
if (typeof editor == 'undefined') {
    editor = new IMSoftcrop.Editor(
            'crop_impl',
            {
                autocrop: true,
                detectWorkerUrl: '/cropjs/js/imcrop.worker.detect.js',
                detectThreshold: 20,
                detectStepSize: 2.5,
                debug: false,
                debugElement: document.getElementById('imc_debug')
            }
    );

    // Add save handler
    editor.onSave(function (cropdata) {

    });

    // Add cancel handler
    editor.onCancel(function (cropdata) {

    });
}

Add image and predefined crop dimensions

editor.addImage(
        image.src,
        function (addedImage) {
            this.addSoftcrop('1:1', true, 1, 1);
            this.addSoftcrop('16:9', false, 16, 9);
            this.addSoftcrop('3:2', false, 3, 2);

            this.addSoftcrop('fixed', false, 800, 400, 100, 20);
        }
);

Development

Install dependencies

npm install

Useful commands

npm run dev         // Start development server located at http://localhost:8000, and file watch
npm run build       // Build and minify files for project
npm run release:[major||minor||hotfix] // Bump version in package.json and package-lock.json then commit files
./publish.sh        // Publish a new version to NPM

Use in local dev writer

Simply change index.html in Writer project.

Swap this:

    <script src="/dist/cropjs/js/tracking.min.js?v=2.1.0"></script>
    <script src="/dist/cropjs/js/cropjs.min.js?v=2.1.0"></script>
    <link href="/dist/cropjs/css/imcrop.css?v=2.1.0" rel="stylesheet" type="text/css" />

for this:

    <!--
    <script src="/dist/cropjs/js/tracking.min.js?v=2.1.0"></script>
    <script src="/dist/cropjs/js/cropjs.min.js?v=2.1.0"></script>
    <link href="/dist/cropjs/css/imcrop.css?v=2.1.0" rel="stylesheet" type="text/css" />
    -->

    <script src="http://localhost:8000/cropjs/js/tracking.js"></script>
    <script src="http://localhost:8000/cropjs/js/cropjs.js"></script>
    <link href="http://localhost:8000/cropjs/css/imcrop.css" rel="stylesheet" type="text/css" />

References

Using tracking.js for feature and face detection.

cropjs's People

Contributors

christofferekberg avatar dannelundqvist avatar dependabot[bot] avatar elmona avatar jarnesjo avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

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

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.