Coder Social home page Coder Social logo

antd-img-crop's Introduction

Link in bio to widgets, your online home screen. ➫ 🔗 kee.so


antd-img-crop

An image cropper for Ant Design Upload

npm npm npm bundle size GitHub npm type definitions

English | 简体中文

Install

pnpm add antd-img-crop
# or
yarn add antd-img-crop
# or
npm i antd-img-crop

Usage

import { Upload } from 'antd';
import ImgCrop from 'antd-img-crop';

const Demo = () => (
  <ImgCrop>
    <Upload>+ Add image</Upload>
  </ImgCrop>
);

Edit antd-img-crop

Props

Prop Type Default Description
quality number 0.4 Cropped image quality, 0 to 1
fillColor string 'white' Fill color for cropped image
zoomSlider boolean true Enable zoom adjustment
rotationSlider boolean false Enable rotation adjustment
aspectSlider boolean false Enable aspect adjustment
showReset boolean false Show reset button to reset zoom rotation aspect
resetText string Reset Reset button text
aspect number 1 / 1 Aspect of crop area , width / height
minZoom number 1 Minimum zoom factor
maxZoom number 3 Maximum zoom factor
cropShape string 'rect' Shape of crop area, 'rect' or 'round'
showGrid boolean false Show grid of crop area (third-lines)
cropperProps object - react-easy-crop props (* existing props cannot be overridden)
modalClassName string '' Modal classname
modalTitle string 'Edit image' Modal title
modalWidth number string Modal width
modalOk string Ok button text
modalCancel string Cancel button text
onModalOk function - Callback of click ok button
onModalCancel function - Callback of click cancel button (or modal mask & top right "x")
modalProps object Ant Design Modal props (* existing props cannot be overridden)
beforeCrop function - Callback before crop modal, if return false or reject(), modal will not open

FAQ

ConfigProvider not work?

Try to set libraryDirectory('es' or 'lib') to babel-plugin-import config, see which one will work.

module.exports = {
  plugins: [
    ['import', { libraryName: 'antd', libraryDirectory: 'es', style: true }],
  ],
};

No style? (only antd<=v4)

If you use antd<=v4 + babel-plugin-import, and no Modal or Slider were imported, please import these styles manually:

import 'antd/es/modal/style';
import 'antd/es/slider/style';

License

MIT License (c) nanxiaobei

antd-img-crop's People

Contributors

0x-jerry avatar clement9527 avatar dependabot[bot] avatar ethanswe avatar jambo2018 avatar labithiotis avatar limichange avatar matulef avatar mirofte avatar nanxiaobei avatar rahulatrecorem avatar ruige24601 avatar samyarkd avatar skyplor avatar tangbzai avatar trung-tran-sts avatar zhoujingsai avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

antd-img-crop's Issues

import "index.less" 文件解析错误

nextjs 中不会解析node_modules中的less文件,导致报错
建议:

  1. 实现 babel-plugin-import 支持
  2. 源码中不显示 import "index.less",由用户手动引用

Contain props not working in mobile

Working like a charm on desktop, but contain is not working on mobile devices.

<ImgCrop width={350} height={200} contain={true}>
          <Upload
            action="https://www.、/v2/5cc8019d300000980a055e76"
            listType="picture-card"
            fileList={fileList}
            onPreview={this.onPreview}
            onChange={this.onChange}
          >
            {fileList.length < 3 && "+ Upload"}
          </Upload>
</ImgCrop>
<Modal visible={previewShow} onCancel={this.onCancel} footer={null}>
<img src={previewSrc} style={{ maxWidth: "100%" }} alt="preview" />
</Modal>

Extra functionality from `react-image-crop` and modal customization

Is there a way to use the underlying properties of the react-image-crop such as minHeight, minWidth, etc. since this package depends on it? Also, is there a way to customize the Modal component that shows up when cropping (changing the buttons and footer, for example)?
Thank you!

Importing 'antd-img-crop' overriding existing CSS.

Hi,
Need help! I am currently using the plugin and facing an issue, that whenever I import the plugin, It overrides my existing CSS. Any idea why this is happening?

Adding below line of code is creating the issue:
"import ImgCrop from 'antd-img-crop';"

Thanks.

build error with the last version 3.4.2

I am sorry, I have another problem :(

With crop 3.3.0 my build was fine, but with the new version 3.4.2 I got this error

I try many many times install and unistall different version of another packages like nextjs or antd (because I thought is a problem of the new versions of nextjs or antd, but the problem just occurs when I update antd-img-crop to 3.4.2

This is my stable dependencies version. If I update crop the build crashes :(

"dependencies": {
        "@next/bundle-analyzer": "^9.4.4",
        "@reduxjs/toolkit": "^1.3.6",
        "@zeit/next-less": "^1.0.1",
        "antd": "^4.3.3",
        "antd-img-crop": "^3.3.0",
        "isomorphic-unfetch": "^3.0.0",
        "next": "^9.4.4",
        "next-antd-aza-less": "^1.0.2",
        "react": "^16.13.1",
        "react-dom": "^16.13.1",
        "react-redux": "^7.2.0"
    }

Multiple images at once

Hey! Amazing package, thanks for it.

Problem: I need to upload multiple files, is it possible to crop/rotate a few images at once?

When used inside a form with other input elements it clears the data entered after image is uploaded (codesandbox attached).)

Hello, it's me again. When I use the image cropper inside a form which has other input fields the data, which is stored in the component's state, is cleared after I upload the image. Please check the codesandbox attached for a demo. First, enter the name and age, and then add an image using the cropper. You will see that the component's state is cleared after the image is uploaded.

https://codesandbox.io/s/beautiful-torvalds-frxpk?file=/src/App.js

ant-slider is not show

Hello! and thanks for this awesome component ♥

I have this problem, the sliders is not show in the modal.

Test Image 4

打包问题

我用到了你的插件,我发现你这边打包时 打包方式好像是错了。我引用后会报错误。
image
image
可以在打包的时候 把 import 也一起打包了吗? 谢谢啦

Image rotation

Hello @nanxiaobei!

I would like to submit a feature idea: have you considered adding a rotation utility to your component? It already does a great job, but it would be amazing with that. If not, are you open to a pull request? We may be able to do that in our team.

Thanks,

Uncaught Error: 'children' to 'ImgCrop' must be 'Upload' or 'Upload.Dragger'

我代码是这样写的,是包裹了Uplaod的
`

<Upload
action={isWx ? "/api/uploadToWx": url}
listType="picture-card"
fileList={list}
data={extraData}
onPreview={this.handlePreview}
onChange={v => {
// console.log("上传改变", list, fileList);
let file = v.file, fileList = v.fileList;

let index = _.findIndex(fileList, item => item.uid == file.uid);
if(file){
  if(file.status === "done"){
    // console.log("上传成功", v.file);
    let response = v.file.response;
    if(response && response.status === "success"){
      let fileItem = {
        uid: file.uid,
        url: response.url,
        status: "done",
      };
      if(isWx){
        fileItem.wx = response.wx;
      }
      fileList[index] = Object.assign(fileItem);
    }
  }else if(file.status === "uploading"){
    fileList[index] = Object.assign({
      uid: file.uid,
      // url: "",
      status: "uploading",
    });
  }
}
// console.log("上传组件的值改变", newValue);
onChange(fileList);

}}

{list.length >= num ? null : uploadButton}


`

not support `Upload.Dragger`

if (!Upload.type.defaultProps.beforeUpload) throw new Error(ERR_NOT_ONLY_UPLOAD);
Upload.type.defaultProps return undefined with Upload.Dragger

picture crop error in IOS

I have encountered a problem during upload a cropped picture.
When I upload a picture after I cropped it,The picture is displayed as a black photo in IOS.
How can I fix this problem?

[Feature Request] Set height and width relative to image size

I really like the simplicity of antd-img-crop compared to other alternatives. I would like to set the initial dimensions relative to the image size the users uploaded. Is this already possible with antd-img-crop and I missed it or is is it maybe already on your feature roadmap?

上传长图,进入无剪裁框

在用你的组件,首先点个赞。在使用过程中,发现一些问题
1.上传长图,进入无剪裁框
2.点击模态框的时候已经取消裁剪了,但是点击确定按理是不更新图片的

Reopen the modal?

Is there a way to allow the user to reopen the modal for editing again?

在getFieldDecorator中使用ImgCrop的时候会报错,找不到refs,请问有什么解决方法吗?

**背景:**想在表单中使用antd4提供的Imgcrop上传并裁剪图片,使用后发现会报找不到refs,请问有办法解决吗?


代码:

{getFieldDecorator('logo')(
    <ImgCrop>
      <Upload
        action="https://www.mocky.io/v2/5cc8019d300000980a055e76"
        listType="picture-card"
      >
        上传
      </Upload>
    </ImgCrop>
)}

报错信息:
Warning: Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

Modal doesn't display properly

I have this issue with the modal when I click the add button,
the modal doesn't display properly and is positioned in a corner of the screen:

Modal

I'm using:

"antd": "4.2.5"
"ant-design-pro": "4.0.0"

Not custom css.

is it possible to use this with Form.Item?

I am trying to use it with antd form:
<Form.Item {...props} valuePropName="file" getValueFromEvent={returnUploadedFileObject}>


<>
{loading ? : ''} Browse
</>


</Form.Item>

But I am not getting any event in returnUploadedFileObject. Is it possible to bind value with form?

When cropping a file, the size increases exponentially.

  1. The size of the resulting file is many times larger than the original file size. this happens when loading jpeg files.
  2. The resulting file is always of image/png type.

On screenshots, I tried to crop a 10.2mb jpeg image, width 10315px, height 7049px.
Output is 117.1 mb png image, width 7049px, height 7049px;
image
image

When width and height are specified the final image is scaled

Steps to Reproduce:

  • use ImgCrop with the following attributes: width = 200 and height = 200
  • upload an image larger than 200px (say 1200x1600)
  • resize the crop for full image width
  • Click Ok

Expected:

  • uploaded image is 200x200

Actual:

  • uploaded image is 1200x1200

black border on cropped image

Hi, Thank you for a great add-on to enable antd to be able to crop and rotate images.

There are two issues that I have spotted.

  1. Currently when I upload an image without cropping or rotating, there is a thin black border on the left. (or left and top if you were to drag the image so that the top left corner is top left). This seems to only be happening with any jpg image with a predominantly white background that is 180px by 200px. (See screenshot attached of codepen example)
    Screenshot 2020-06-23 at 00 43 38

Sample image that easily replicates the black border when upload:
APic2

  1. When rotating an image that is uploaded, the blank fillspace of the image is black. If I change the background color of the crop container, that can as per the react-easy-crop plugin discussion in the link below allow you to change the background color of the blank fillspace:

https://github.com/ricardo-ch/react-easy-crop/issues/148

see this demo: https://codesandbox.io/s/react-easy-crop-demo-with-cropped-output-m0spo?file=/src/styles.js

I was thinking of adding in a colorpicker ability for the user to be able to pick the background color fillspace or have this be done automatically. Perhaps it could be done where the zoom/crop slider is on the popup using something like this: https://github.com/casesandberg/react-color

Using antd-img-crop, How would I be able to change the background color of the fillspace? Would I need to pass in an extra prop?

I thank you in advance.

Allow only images

When I upload a file like a pdf or a video the cropper doesn't display anything and If I click Ok now I get an error. I want to put restrictions on extensions allowed how to do it? How to handle this error.
demo link

error with the last version of andt + antd-img-crop

Hi. I had

        "antd": "^4.3.1",
        "antd-img-crop": "^3.3.0",

I update to

        "antd": "^4.3.3",
        "antd-img-crop": "^3.4.1",

Now I am getting this error, everytime I push F5 in a component with antd-img-crop (server side error):

使用umi ssr打包报错

报错如下image
直接跑项目是没问题的,但是一打包就报错。使用的架构,umijs 2.8.9,@umijs/plugin-prerender 1.4.2, antd 3.22.0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.