跳至正文
rdlabo.dev文档

Photo Editor

通过 Ionic Modal,从按钮或现有页面方法中调用PhotoEditorPage。请在安装步骤之后执行此操作。

import { Component, inject } from '@angular/core';
import type { ApplicationConfig } from '@angular/core';
import { ModalController, IonButton } from '@ionic/angular';
import { PhotoEditorProps, PhotoEditorResult, providePhotoEditor } from '@rdlabo/ionic-angular-photo-editor';
import { PhotoEditorPage } from '@rdlabo/ionic-angular-photo-editor/editor';
import { createTuiImageEditor } from '@rdlabo/ionic-angular-photo-editor/editor/tui';

export const appConfig: ApplicationConfig = {
  providers: [providePhotoEditor({ createImageEditor: createTuiImageEditor })],
};

@Component({
  selector: 'app-edit-photo',
  imports: [IonButton],
  template: `<ion-button type="button" (click)="openEditor()">Edit photo</ion-button>`,
})
export class EditPhotoPage {
  private readonly modalCtrl = inject(ModalController);

  async openEditor(): Promise<void> {
    const componentProps = {
      requireSquare: false,
      value: 'https://picsum.photos/200/300',
      toolbarColorScheme: 'dark',
      labels: {
        save: '送信', // 覆盖默认值 '保存'
      },
    } satisfies PhotoEditorProps;
    const modal = await this.modalCtrl.create({
      component: PhotoEditorPage,
      componentProps,
    });
    await modal.present();
    const { data } = await modal.onWillDismiss<PhotoEditorResult>();
    if (data?.action === 'save') {
      console.log(data.value);
    }
  }
}

模态框返回的结果

保存后,模态框关闭并返回以下数据:

interface PhotoEditorResult {
  action: 'save';
  value: string; // 编辑后图片的数据 URL
}

未保存便关闭时,模态框不返回数据。

选项

requireSquare: boolean

当值为true时,在继续编辑之前,图像必须被裁剪为正方形格式。

value: string

需要编辑的图像 URL 或数据 URL。

toolbarColorScheme: 'light' | 'dark'

**必填。**深色或黑色的 ion-toolbar 使用 dark,浅色或白色的工具栏使用 light。库无法根据 CSS、半透明效果或运行时的主题覆盖可靠地推断最终外观。请参阅主题。

labels: Partial<PhotoEditorLabels>

可以覆盖默认的 UI 字符串设置。如果未指定某个键的值,则仍然使用内置的日语默认值。

键 默认值(日语)
save 保存
close 閉じる
back 戻る
apply 適用
crop 切り抜き・回転
rotate 回転
cropCover 画像に合わせる
crop16x9 16対9
cropSquare 正方形
cropFree 自由
filter フィルター
brightness 明るさ
original オリジナル
invert 反転
sepia セピア
vintage ヴィンテージ
blur ぼかし
grayscale グレースケール
sharpen 輪郭
emboss エンボス