Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

后端开发者,发现当前不支持gif的裁剪,进行修改。可参考。 #9011

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"dependencies": {
"path-to-regexp": "^6.2.0",
"postcss": "^8.4.14",
"qs": "6.9.7"
"qs": "6.9.7",
"super-image-cropper": "^1.0.18"
},
"devDependencies": {
"@babel/generator": "^7.22.9",
Expand Down
43 changes: 35 additions & 8 deletions packages/amis/src/renderers/Form/InputImage.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {Suspense} from 'react';

Check failure on line 1 in packages/amis/src/renderers/Form/InputImage.tsx

View workflow job for this annotation

GitHub Actions / build (16.x)

Type 'string | Blob' is not assignable to type 'FileX'.
import {
FormItem,
FormControlProps,
Expand All @@ -10,7 +10,13 @@
PlainObject
} from 'amis-core';
// import 'cropperjs/dist/cropper.css';
const Cropper = React.lazy(() => import('react-cropper'));


import Cropper from 'react-cropper';
import {SuperImageCropper} from 'super-image-cropper';

const imageCropper = new SuperImageCropper();

import DropZone from 'react-dropzone';
import {FileRejection, ErrorCode, DropEvent} from 'react-dropzone';
import 'blueimp-canvastoblob';
Expand Down Expand Up @@ -1100,18 +1106,39 @@

handleCrop() {
const {cropFormat, cropQuality} = this.props;
this.cropper.getCroppedCanvas().toBlob(
(file: File) => {
this.addFiles([file]);

imageCropper
.crop({
cropperInstance: this.cropper,
// src: this.cropper.url,
gifJsOptions: {
quality: cropQuality || 1
},
outputType: 'blob' // optional, default blob url
})
.then(blob => {
this.addFiles([blob]);
this.setState({
cropFile: undefined,
locked: false,
lockedReason: ''
});
},
cropFormat || 'image/png',
cropQuality || 1
);
cropFormat || 'image/png';
// cropQuality || 1
});

// this.cropper.getCroppedCanvas().toBlob(
// (file: File) => {
// this.addFiles([file]);
// this.setState({
// cropFile: undefined,
// locked: false,
// lockedReason: ''
// });
// },
// cropFormat || 'image/png',
// cropQuality || 1
// );
}

cancelCrop() {
Expand Down
Loading