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

noodle-ng-image-crop

v0.6.0

Published

Angular image cropping component. It is a port of directive-based code from https://github.com/bcabanes/angular-image-cropper to an Angular 11 component.

Downloads

103

Readme

NoodleNgImageCrop

Description

Angular image cropping component.

The image can be zoomed/rotated, and then cropped. It is responsive, and works under mouse and/or touch events.

This is a port of directive-based code from https://github.com/bcabanes/angular-image-cropper to an Angular (v8 and above) component.

Installation

NPM

Install from npm using

npm install noodle-ng-image-crop

Yarn

Yarn configuration supports packaging via ng-packagr.

Install ng-packagr and Yarn and run the package script from the command line.

yarn package

Copy contents of dist to node_modules/NoodleNgImageCrop in your project folder.

Usage

Import Module/Component

import { NoodleNgImageCrop } from "noodle-ng-image-crop";

@NgModule({
  declarations: [
    NoodleNgImageCrop
    ...
  ],
  imports: [ ... ],
  providers: [ ... ],
  bootstrap: [ ... ]
})
export class AppModule { }

Add to Component

Add the component to your template.

  <noodle-ng-image-crop (onCrop)="onCrop($event)"
                        [cropHeight]="300"
                        [cropWidth]="200"
                        [centerOnInit]="true"
                        [imageSource]=""></noodle-ng-image-crop>

Options

Options can be set on the component:

  • imageSource string URI for image source to crop, can be a URL or base64 data.
  • actionButtons Array array of buttons to display in the control panel.
  • zoom-step number Zoom step. Defaults to 0.1;
  • show-controls boolean Display or not the control buttons (true by default)
  • fit-on-init boolean Fit the image on initialization (maintains aspect ratio)
  • center-on-init boolean Center the image on initialization (maintains aspect ratio)
  • cropHeight number Height of the crop (and display height of bounding box).
  • cropWidth number Width of the crop (and display width of bounding box).
  • maxZoom number Restricts zoom applied to the image to be below a maximum scale.
  • minZoom number Forces zoom applied to the image to be above a minimum scale.

Handling Output

The crop action emits an onCrop event which can be handled by the parent component. The event emits an NoodleNgImageCropData object.

import { NoodleNgImageCropData } from "noodle-ng-image-crop";

@component {
  ...

  croppedOutput: NoodleNgImageCropData;

  onCrop($event) {
    this.croppedOutput = $event;
  }
}

Models

The NoodleNgImageCropActionButton model contains details bound to the action controls at run time, allowing customisation of label.

  // Action that the button represents. Maps via NoodleNgImageCropAction enumeration to a set of supported actions.
  action: NoodleNgImageCropAction;

  // Text label applied to the button.
  text: string;

  // Css class applied to the button.
  cssClass: string;

The NoodleNgImageCropAction enumeration allows mapping of buttons to supported actions.

  rotateLeft = 1,
  rotateRight,
  zoomIn,
  zoomOut,
  zoomToFit,
  crop

The NoodleNgImageCropData model contains details of the crop applies and is output by the onCrop event. It contains the following:

  // Scaling applied to the source image on crop (effectively zoom factor)
  scale: number = 1;

  // Image rotation on crop
  degrees: number = 0;

  // Pixel based crop position and size
  x: number = 0;
  y: number = 0;
  w: number = 1;  
  h: number = 1;

  // Percentage based crop position and size
  xPercent: number = 0;
  yPercent: number = 0;
  wPercent: number = 1;
  hPercent: number = 1;

  // base64 data URI for the cropped image
  croppedImage: string;

Angular Versions

| Version | Angular Version | | --- | --- | | 0.6.0 | ^14.0.0 | | 0.5.0 | ^13.0.0 | | 0.4.0 | ^12.0.0 | | 0.3.0 | ^11.0.0 | | 0.2.0 | ^10.0.0 | | 0.1.0 | ^9.0.0 | | 0.0.14 | ^8.0.0 |