Skip to main content

upp-image

A versatile image component with built-in cropping, lazy loading, EXIF orientation handling, and base64 conversion. It integrates with Angular reactive forms as a ControlValueAccessor, supporting both readonly display and editable modes where users can select and crop images through a modal interface.

When to Use

  • You need to display an image that may come from a URL or a base64 string.
  • You want to let users pick and crop an image before uploading (editable mode).
  • You need an image input that works inside Angular reactive forms.
  • You need automatic EXIF orientation correction for user-uploaded photos.
  • You want lazy loading and preload/cache integration for server-hosted images.

Demo

Source Code

<div class="demo-scroll-container">
<upp-scrollable [scrollbar]="'y'">
<div class="demo-content">
<h2>upp-image</h2>
<p class="demo-description">Product photo display &amp; editing — toggle the lock to switch between readonly and editable modes.</p>

<!-- Controls -->
<div class="demo-controls">
<ion-button size="small" (click)="toggleReadonly()">
<ion-icon name="lock-closed-outline" slot="start" *ngIf="isReadonly"></ion-icon>
<ion-icon name="lock-open-outline" slot="start" *ngIf="!isReadonly"></ion-icon>
Editable: {{ !isReadonly }}
</ion-button>

<div class="demo-control-group">
<label class="demo-label">Crop width</label>
<input type="number" [(ngModel)]="crwidth" class="demo-number-input">
</div>

<div class="demo-control-group">
<label class="demo-label">Crop height</label>
<input type="number" [(ngModel)]="crheight" class="demo-number-input">
</div>
</div>

<!-- Updated banner -->
<div class="demo-toast" *ngIf="imageUpdated">
<ion-icon name="checkmark-circle-outline"></ion-icon>
Image updated!
</div>

<!-- Single image: toggles readonly/editable -->
<div class="demo-section">
<h3>Product Photo ({{ isReadonly ? 'readonly' : 'editable' }})</h3>
<p class="demo-label">{{ isReadonly ? 'Click the lock to enable editing.' : 'Change/Delete overlay the image.' }}</p>
<div class="image-frame">
<upp-image #imageRef
[src]="imageSrc"
[readonly]="isReadonly"
[crwidth]="crwidth"
[crheight]="crheight"
(Changed)="onImageChanged(imageRef)">
</upp-image>
</div>
</div>
</div>
</upp-scrollable>
</div>

API Reference

upp-image

Selector: upp-image

Implements: ControlValueAccessor, OnInit, OnChanges, OnDestroy

Inputs

NameTypeDefaultDescription
readonlybooleantrueWhen true, the image is display-only. When false, the user can select a file and crop the image.
srcstring | nullnullImage source. Can be a URL or a base64 string.
crheightstring'0'Crop height constraint in pixels (passed to the crop modal).
crwidthstring'0'Crop width constraint in pixels (passed to the crop modal).
formControlNamestring''Name of the reactive form control this component is bound to.
valuestring | null(derived)The current image value (base64 or URL). Supports two-way binding via ControlValueAccessor.

Outputs

NameTypeDescription
ChangedEventEmitter<any>Emits whenever the image is modified (file selected, cropped, or cleared).

Computed Properties

PropertyTypeDescription
IsCachedbooleanWhether the current src is available in the preload cache.
IsVisiblebooleantrue if the image has loaded or is cached.
Base64Promise<string | null>Asynchronously returns the base64-encoded PNG representation of the current image.

upp-modal-crop-image

Selector: upp-modal-crop-image

Internal modal component used by upp-image for cropping. Not intended for direct use.

NameTypeDescription
@Input() imageanyThe image element to crop.
@Input() heightnumberDesired crop height.
@Input() widthnumberDesired crop width.