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

ng-image-canvas

v1.0.1

Published

An Angular library for dragging, dropping, and resizing images on a canvas

Downloads

22

Readme

ng-image-canvas

ng-image-canvas is an Angular library that provides a canvas component where users can drag and drop images, move them around, resize them, and remove them. The component supports enabling or disabling editing, and maintains the aspect ratio when resizing with the Shift key.

Installation

To install the library, use the following command:

  npm install ng-image-canvas

Usage

Importing the Module

First, import the NgImageCanvasModule into component

import { Component } from "@angular/core";
import { RouterOutlet } from "@angular/router";
import { NgImageCanvasModule } from "ng-image-canvas";

@Component({
  selector: "app-root",
  standalone: true,
  imports: [RouterOutlet, NgImageCanvasModule],
  templateUrl: "./app.component.html",
  styleUrl: "./app.component.scss",
})
export class AppComponent {}

Using the Component

You can use the ng-image-canvas component in your template as shown below:

<ng-image-canvas
  [width]="800"
  [height]="600"
  [editing]="editingEnabled"
  [resizeHandleSize]="10"
  [resizeHandleColor]="'gray'"
  [closeButtonSize]="20"
  [closeButtonBackgroundColor]="'red'"
  [closeButtonFontColor]="'white'"
  (imagesChange)="onImagesChange($event)"
  #canvasComp
>
</ng-image-canvas>
<button (click)="toggleEditing()">Toggle Editing</button>
<button (click)="logImages()">Log Images</button>
<button (click)="addImage()">Add Image</button>

In your component, you can handle the image changes and control the editing state:

import { Component, ViewChild } from "@angular/core";
import { RouterOutlet } from "@angular/router";
import { DraggableImage, NgImageCanvasModule } from "ng-image-canvas";

@Component({
  selector: "app-root",
  standalone: true,
  imports: [RouterOutlet, NgImageCanvasModule],
  templateUrl: "./app.component.html",
  styleUrls: ["./app.component.css"],
})
export class AppComponent {
  editingEnabled: boolean = true;
  @ViewChild("canvasComp") canvasComp;

  toggleEditing(): void {
    this.editingEnabled = !this.editingEnabled;
  }

  onImagesChange(images: DraggableImage[]): void {
    console.log("Images changed:", images);
  }

  logImages(): void {
    console.log(this.canvasComp.getImages());
  }

  addImage(): void {
    const newImage: DraggableImage = {
      img: new Image(),
      x: 0,
      y: 0,
      width: 100,
      height: 100,
    };
    newImage.img.src = "https://via.placeholder.com/100";
    newImage.img.onload = () => {
      const images = this.canvasComp.getImages();
      images.push(newImage);
      this.canvasComp.setImages(images);
    };
  }
}

Documentation

Inputs

  • width: number: The width of the canvas.
  • height: number: The height of the canvas.
  • editing: boolean: Enables or disables editing. When editing is true, users can move, resize, and remove images.
  • resizeHandleSize: number: The size of image resize handle.
  • resizeHandleColor: string: The color of image resize handle.
  • closeButtonSize: number: Size of image remove button.
  • closeButtonBackgroundColor: string: The background color of image remove button
  • closeButtonFontColor: string: The color of 'x' on image remove button.

Outputs

  • imagesChange: EventEmitter<DraggableImage[]>: Emits the current list of images whenever they are added, moved, resized, or removed.

Methods

  • getImages(): DraggableImage[]: Returns the current list of images on the canvas.
  • setImages(images: DraggableImage[]): void: Sets the list of images on the canvas and redraws it.

Screenshots

Canvas with Editing Enabled

Canvas with Editing Enabled

Canvas with Editing Disabled

Canvas with Editing Disabled

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Contributing

Contributions are welcome. You can start by looking at issues or creating new Issue with proposal or bug report.