Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

auto-clippath

rjct21MIT1.0.5TypeScript support: included

The TypeScript-based library for clip-path generation

auto clip path, auto clippath, auto path, clippath generation, clippath, css clip path, css clippath, path generation, paths generate, star shape, svg clip path, svg mask, svg path, svg patterns, svg transform, svg, vector graphics

readme

auto-clippath

GitHub package.json version NPM

TypeScript-based library for generating CSS/SVG clipPath coordinates from images with transparent backgrounds.

Demo

TypeScript Usage

To use the library with TypeScript, you need to install the module using npm: npm install auto-clippath

Or using Yarn: yarn add auto-clippath Then you can import any function as follows:

import autoClipPath from 'auto-clippath';

const { clipPath } = await autoClipPath(
    HTMLImageElement,
    { width: 100, height: 200 },

    // Optional
    { 
        gap: 5,                 // Additional space around the detected area
        distance: 5,            // Minimal distance between path points
        shift: { x: 5, y: 5 }   // Shift detected area, useful for sprites
    }
); // returns array of path points { x: number, y: number }[]

Browser Usage

The library can also be used directly in browsers without TypeScript. First, download the auto-clippath.min.js file from the GitHub repository. Then use the autoClipPath or window.autoClipPath.

<script src="auto-clippath-browser.mjs" type="module"></script>
<script>
    const { clipPath } = await autoClipPath(
        HTMLImageElement, 
        { width: 100, height: 200 },

        // Optional
        {
            gap: 5,                 // Additional space around the detected area
            distance: 5,            // Minimal distance between path points
            shift: { x: 5, y: 5 }   // Shift detected area, useful for sprites
        }
    );

    console.log(clipPath);  // Array of path points { x: number, y: number }[]