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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bitforgehq/angular-ionic-image-cropper

v0.1.2

Published

An Ionic Angular library for cross platform image cropping.

Readme

Angular Ionic Image Cropper

A lightweight Angular library for image cropping with Ionic integration. This library provides a simple and customizable image cropper component that works seamlessly with Ionic applications.

Features

  • 🖼️ Image Cropping: Crop images with customizable aspect ratios
  • 📱 Ionic Integration: Built specifically for Ionic applications
  • 📷 Camera Support: Optional camera integration via Capacitor
  • 📦 Lightweight: Minimal dependencies
  • 🔧 TypeScript: Full TypeScript support

Installation

npm install @bitforgehq/angular-ionic-image-cropper

Import Global Styles (Recommended)

To ensure proper styling, especially for iOS builds, import the global styles in your application:

In your main styles file (e.g., src/styles.scss):

@use '@bitforgehq/angular-ionic-image-cropper/index.scss';

Or in your angular.json:

{
  "styles": [
    "src/styles.scss",
    "node_modules/@bitforgehq/angular-ionic-image-cropper/index.scss"
  ]
}

Note: The styles are automatically included when you import the library, but for iOS builds, it's recommended to explicitly import the styles to ensure proper functionality. This library includes iOS-specific fixes for common rendering issues.

Dependencies

This library requires the following peer dependencies:

{
  "@angular/common": "^20.1.0",
  "@angular/core": "^20.1.0",
  "@ionic/angular": "^8.0.0"
}

For camera functionality, install the optional dependency:

npm install @capacitor/camera

Usage

1. Import the Module

In your Angular module or standalone component:

import { ImageCropperComponent, ImageCropperService } from '@bitforgehq/angular-ionic-image-cropper';

@Component({
  // ... your component config
  imports: [ImageCropperComponent]
})
export class YourComponent {
  private imageCropperService = inject(ImageCropperService);
}

2. Basic Usage

Using the Service (Recommended)

import { ImageCropperService, ImageCropperConfig } from '@bitforgehq/angular-ionic-image-cropper';

export class YourComponent {
  private imageCropperService = inject(ImageCropperService);

  async cropImage() {
    try {
      // Open cropper with an image URL
      const croppedBlob = await this.imageCropperService.openCropper(
        'path/to/your/image.jpg',
        {
          aspectRatio: 16 / 9,   // optional, defaults to 16/9
          cancelText: 'Cancel',  // optional, defaults to 'Cancel'
          doneText: 'Done'       // optional, defaults to 'Done'
        }
      );
      
      console.log('Cropped image:', croppedBlob);
    } catch (error) {
      console.error('Crop cancelled or failed:', error);
    }
  }

  async takeAndCropPhoto() {
    try {
      // Take a photo and crop it
      const croppedBlob = await this.imageCropperService.takeAndCropPhoto({
        aspectRatio: 1,                // square aspect ratio
        cancelText: 'Cancel',          // 'cancel' button text
        doneText: 'Done',              // 'confirm' button text
        quality: 0.8,                  // 80% quality
        outputFormat: 'image/png'      // PNG format
      });
      
      console.log('Cropped photo:', croppedBlob);
    } catch (error) {
      console.error('Photo capture or crop failed:', error);
    }
  }
}

API Reference

ImageCropperService

Configuration Interface

interface ImageCropperConfig {
  /**
   * Text to display on the cancel button
   * @default 'Cancel'
   */
  cancelText?: string;
  
  /**
   * Text to display on the done/confirm button
   * @default 'Done'
   */
  doneText?: string;
  
  /**
   * Aspect ratio for the crop area (width / height)
   * Common values: 1 (square), 16/9 (widescreen), 4/3 (standard)
   * @default 16/9
   */
  aspectRatio?: number;
  
  /**
   * Quality of the output image (0.1 to 1.0)
   * @default 0.9
   */
  quality?: number;
  
  /**
   * Output format for the cropped image
   * @default 'image/jpeg'
   */
  outputFormat?: 'image/jpeg' | 'image/png' | 'image/webp';
}

Methods

  • openCropper(imagePath: string, config?: ImageCropperConfig): Promise<Blob>

    • Opens the cropper modal with the specified image
    • Returns a Promise that resolves to the cropped image as a Blob
    • Throws an error if the crop is cancelled
  • takeAndCropPhoto(config?: ImageCropperConfig): Promise<Blob>

    • Opens the camera, takes a photo, then opens the cropper
    • Returns a Promise that resolves to the cropped image as a Blob
    • Requires @capacitor/camera to be installed

Browser Support

This library supports all modern browsers that support:

  • ES2015+ features
  • Canvas API
  • File API

Troubleshooting

iOS Build Issues

If you experience rendering issues on iOS builds, ensure you have imported the global styles:

// In your global styles file
@use '@bitforgehq/angular-ionic-image-cropper/index.scss';

Cropper Not Displaying Properly

If the cropper modal doesn't display correctly, check that:

  1. The cropper CSS is properly imported
  2. Your app has proper viewport meta tags
  3. The modal container has sufficient z-index

License

MIT

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.