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

@tato30/vue-polygon-cropper

v0.1.0

Published

A polygon cropper built in top of fabric.js

Downloads

5

Readme

vue-polygon-cropper

[!WARNING] This component is still in active development and only early versions has been released. Any recommendation, feature propose or bug report feel free to open an Issue or PR 😊

Introduction

VuePolygonCropper is a Vue 3 component built-in in top of fabric.js to crop an image with polygon shapes.

Installation

npm i @tato30/vue-polygon-cropper
yarn add @tato30/vue-polygon-cropper

Basic Usage

<script setup lang="ts">
import { ref } from 'vue';
import { VuePolygonCropper } from '@tato30/vue-polygon-cropper'
</script>

<template>
  <vue-polygon-cropper src="https://domain/images/image1.jpg" :width="500" />
</template>

Props

src

Type: string Required: true

The URL to create an image from.

<vue-polygon-cropper src="https://domain/images/image1.jpg" />

width

Type: number Required: false

The width to scale the image on the canvas element, otherwise the canvas will render with the image dimensions.

height

Type: number Required: false

The height to scale the image on the canvas element, otherwise the canvas will render with the image dimensions.

This prop has less precedence than width.

no-background

Type: boolean Default: false Required: false

Remove the background shape.

background-color

Type: string Default: rgba(0, 0, 0, 0.7) Required: false

Set the background color.

points

Type: array Required: false

An array of cartesian points to shape an initial polygon on the image, the points must be calculated in base of the image's dimensions and can be set 1 or n points.

By default, the component creates four points for each corner of the image.

<vue-polygon-cropper
  src="https://domain/images/image1.jpg" 
  :points="[
    { x: 149, y: 1626 },
    { x: 1321, y: 1248 },
    { x: 1437, y: 41 },
    { x: 132, y: 212 },
    { x: 723, y: 920 },
    { x: 1202, y: 928 }
  ]"
/>

lines

Type: object | Line Required: false

Specify the style of the lines drawn between points.

Default (All properties are optional):

{
  "color": "white", // Line color
  "width": 1.5, // Line width in px
  "dash": [7, 5] // Dash array [dash, space], use [0, 0] for a thin line, in px
}
<vue-polygon-cropper
  src="https://domain/images/image1.jpg" 
  :lines="{
    width: 1,
    dash: [0, 0] 
  }"
/>

handlers

Type: object | Handler Required: false

Specify the style of the handlers drawn by each point.

Default (All properties are optional):

{
  "type": "rect", // Shape: "circle" or "rect"
  "color": "white", // Shape's fill color
  "borderColor": "#78a6f1", // Shape's border color
  "borderWidth": 0.5, // Shape's border width in px
  "padding": 10, // Padding of the movable area of the handler in px
  "width": 10, // Width of the 'rect' handler in px
  "height": 10, // Height of the 'rect' handler in px
  "radius": 5, // Radius of the 'circle' handler in px
}
<vue-polygon-cropper
  src="https://domain/images/image1.jpg" 
  :handlers="{
    borderWidth: 1,
    padding: 15,
    width: 7,
    height: 7,
  }"
/>

Events

loaded

Emitted once the image has been loaded.

<vue-polygon-cropper src="https://domain/images/image1.jpg" @loaded="onLoaded" />

moving

Emitted when a point has been moved.

<vue-polygon-cropper src="https://domain/images/image1.jpg" @loaded="onMoving" />

The payload value contains the coordinates of all points in the canvas and scaled to image's dimensions

Example:

{
  // Coordinates based on canvas
  "canvas": [ 
    {
      x: 120,
      y: 52
    },
    {
      x: 620,
      y: 80
    },
    {
      x: 690,
      y: 240
    },
    {
      x: 90,
      y: 300
    }
  ],
  // Coordinates scaled in base image's dimensions (scale: 2, in this example)
  "image": { 
    {
      x: 240,
      y: 104
    },
    {
      x: 1240,
      y: 160
    },
    {
      x: 1380,
      y: 480
    },
    {
      x: 180,
      y: 600
    }
  }
}