--- order: 14 title: zh-CN: 上传前裁切图片 en-US: Crop image before uploading --- ## zh-CN 配合 [antd-img-crop](https://github.com/nanxiaobei/antd-img-crop) 实现上传前裁切图片。 ## en-US Use [antd-img-crop](https://github.com/nanxiaobei/antd-img-crop) to crop image before uploading. ```jsx import React, { useState } from 'react'; import { Upload } from 'antd'; import ImgCrop from 'antd-img-crop'; const Demo = () => { const [fileList, setFileList] = useState([ { uid: '-1', name: 'image.png', status: 'done', url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png', }, ]); const onChange = ({ fileList: newFileList }) => { setFileList(newFileList); }; const onPreview = async file => { let src = file.url; if (!src) { src = await new Promise(resolve => { const reader = new FileReader(); reader.readAsDataURL(file.originFileObj); reader.onload = () => resolve(reader.result); }); } const image = new Image(); image.src = src; const imgWindow = window.open(src); imgWindow.document.write(image.outerHTML); }; return ( {fileList.length < 5 && '+ Upload'} ); }; export default Demo; ```