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 πŸ™

Β© 2026 – Pkg Stats / Ryan Hefner

@osmanabd/ngx-image-upload-preview

v2.0.11

Published

πŸš€ A feature-rich Angular image upload component with preview, validation, **automatic compression**, zoom capabilities, and full form integration.

Readme

ngx-image-upload

πŸš€ A feature-rich Angular image upload component with preview, validation, automatic compression, zoom capabilities, and full form integration.

ngx-image-upload


✨ Features

  • πŸ“· Image Upload & Preview with drag-and-drop support
  • πŸ” Interactive Preview Modal with zoom/pan capabilities
  • βœ… Comprehensive Validation (file type, size, required)
  • πŸ“‰ Automatic Image Compression before upload (configurable)
  • 🎨 Customizable UI with CSS Variables and templates
  • πŸ“± Responsive Design with adjustable dimensions
  • β™Ώ Accessibility First (ARIA labels, keyboard navigation)
  • πŸ“¦ Standalone Component with zero dependencies
  • ⚑ Smooth Animations & loading states

πŸš€ Installation

npm install @osmanabd/ngx-image-upload-preview

πŸ“Œ Basic Usage

import { ImageUploadComponent } from '@osmanabd/ngx-image-upload-preview';

Reactive Forms Example

<form [formGroup]="profileForm" (ngSubmit)="onSubmit()">
  <ngx-image-upload 
    formControlName="avatar"
    [required]="true"
    [maxSizeMB]="5"
    [compress]="true"
    [compressionOptions]="{ maxSizeMB: 1, maxWidthOrHeight: 1024, initialQuality: 0.8 }"
    [allowedTypes]="['image/jpeg', 'image/png', 'image/webp']"
    previewTitle="Profile Preview"
    requiredMessage="Please upload a profile photo"
    (fileSelected)="handleFile($event)">
  </ngx-image-upload>
  
  <button type="submit">Save Profile</button>
</form>

Template-driven Forms Example

<ngx-image-upload
  [(ngModel)]="user.avatar"
  name="avatar"
  [compress]="true"
  [compressionOptions]="{ maxSizeMB: 1 }"
  [defaultImage]="'assets/default-avatar.png'">
</ngx-image-upload>

πŸ“‰ Image Compression

To reduce file size and optimize uploads, ngx-image-upload supports automatic client-side image compression.

πŸ”§ Compression Options

| Input | Type | Default | Description | |--------------------|----------|---------|-----------------------------------------------------------------------------| | compress | boolean | false | Enable/disable image compression before upload | | compressionOptions | object | {} | Compression settings (see below) |

Example Options

compressionOptions = {
  maxSizeMB: 1,             // Target size in MB
  maxWidthOrHeight: 1024,   // Resize image to max width or height
  initialQuality: 0.8       // Quality for JPEG/WebP compression
}

πŸ“± Images taken from iPhones or modern phones (2–5MB) can be reduced to 500KB–1MB depending on resolution and quality.

πŸ–ΌοΈ Unsupported formats (e.g., HEIC, SVG) are auto-converted to JPEG before compression.


πŸ” Preview Modal Features

The interactive preview modal includes:

  • Zoom In/Out controls (0.5x - 5x)
  • Drag-to-Pan functionality when zoomed
  • Reset to Default view
  • Fullscreen Overlay with blurred backdrop

🎨 Customization

ngx-image-upload {
  --primary-color: #4a90e2;
  --error-color: #ff4757;
  --border-radius: 8px;
  --background-color: #f8f9fa;
  --text-color: #2d3436;
  --box-shadow: 0 2px 15px rgba(0,0,0,0.1);
  --transition-speed: 0.3s;
}

βœ… Validation & Error Handling

Built-in Validations:

<ngx-image-upload
  [maxSizeMB]="5"
  [allowedTypes]="['image/jpeg', 'image/png']"
  requiredMessage="Image is required">
</ngx-image-upload>

Validation Scenarios

  1. Required Validation – Displays custom message when no image is selected
  2. File Size Validation – Max size in MB (after compression if enabled)
  3. MIME Type Validation – JPEG, PNG, WebP (wildcards not supported yet)
  4. Custom Error Messages – For localization or branding

πŸ“‹ API Reference

Inputs

| Input | Type | Default | Description | |---------------------|----------|--------------|--------------------------------------| | requiredMessage | string | - | Marks field as required with provided message | | maxSizeMB | number | 2 | Maximum file size in megabytes | | allowedTypes | string[] | ['image/jpeg', 'image/png'] | Allowed MIME types | | previewTitle | string | - | Title shown in preview modal | | showPreviewButton | boolean | true | Toggle preview zoom button | | enablePreviewModal| boolean | true | Enable/disable fullscreen preview | | defaultImage | string | - | Fallback image for errors | | previewButtonLabel| string | "View full size" | Preview Button Label | | width | number | 150 | Preview container width | | height | number | 150 | Preview container height | | src | string | - | Default preview image | | disabled | boolean | false | Disable/Enable input | | compress | boolean | false | Enable automatic image compression | | compressionOptions| object | {} | Options to configure compression |

Outputs

| Output | Type | Description | |---------------------|---------|-----------------------| | fileSelected | File | Emits selected file after validation & compression |


β™Ώ Accessibility Features

  • ARIA Labels for all interactive elements
  • Focus States for visual feedback
  • Screen Reader optimized:
    • Live error announcements
    • Modal interaction labels
    • Status updates during upload

🐞 Troubleshooting

Q: Preview modal not opening?
A: Ensure enablePreviewModal is not set to false and check browser CSP for blob URL issues.

Q: Custom styles not applying?
A: Make sure styles are global or use ::ng-deep if ViewEncapsulation is enabled.

Q: Drag-and-drop not working?
A: Verify no parent elements are intercepting drag events.

Q: Large image not compressing enough?
A: Adjust initialQuality or maxWidthOrHeight in compressionOptions.


πŸ“„ License

MIT License Β© 2025 Osman.
Contributions are welcome! Open an issue or PR on GitHub. πŸš€