image-editor.mdx 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. ---
  2. sidebar_position: 1
  3. slug: /image-editor
  4. ---
  5. import Tabs from '@theme/Tabs';
  6. import TabItem from '@theme/TabItem';
  7. import UppyCdnExample from '/src/components/UppyCdnExample';
  8. # Image editor
  9. Image editor. Designed to be used with the Dashboard UI.
  10. <div style={{ maxWidth: 500 }}>
  11. ![Screenshot of the Image Editor plugin UI in Dashboard](https://user-images.githubusercontent.com/1199054/87208710-654db400-c307-11ea-9471-6e3c6582d2a5.png)
  12. </div>
  13. ## When should I use this?
  14. When you want to allow users to crop, rotate, zoom and flip images that are
  15. added to Uppy.
  16. ## Install
  17. <Tabs>
  18. <TabItem value="npm" label="NPM" default>
  19. ```shell
  20. npm install @uppy/core @uppy/dashboard @uppy/image-editor
  21. ```
  22. </TabItem>
  23. <TabItem value="yarn" label="Yarn">
  24. ```shell
  25. yarn add @uppy/core @uppy/dashboard @uppy/image-editor
  26. ```
  27. </TabItem>
  28. <TabItem value="cdn" label="CDN">
  29. <UppyCdnExample>
  30. {`
  31. import { Uppy, Dashboard, ImageEditor } from "{{UPPY_JS_URL}}"
  32. const uppy = new Uppy()
  33. uppy.use(Dashboard, { target: '#uppy', inline: true })
  34. uppy.use(ImageEditor)
  35. `}
  36. </UppyCdnExample>
  37. </TabItem>
  38. </Tabs>
  39. ## Use
  40. ```js {3,7,11} showLineNumbers
  41. import Uppy from '@uppy/core';
  42. import Dashboard from '@uppy/dashboard';
  43. import ImageEditor from '@uppy/image-editor';
  44. import '@uppy/core/dist/style.min.css';
  45. import '@uppy/dashboard/dist/style.min.css';
  46. import '@uppy/image-editor/dist/style.min.css';
  47. new Uppy()
  48. .use(Dashboard, { inline: true, target: '#dashboard' })
  49. .use(ImageEditor);
  50. ```
  51. ## API
  52. ### Options
  53. :::info
  54. If you automatically want to open the image editor when an image is added, see
  55. the [`autoOpen`](/docs/dashboard#autoopen) Dashboard option.
  56. :::
  57. #### `id`
  58. A unique identifier for this plugin (`string`, default: `'ImageEditor'`).
  59. #### `quality`
  60. Quality Of the resulting blob that will be saved in Uppy after editing/cropping
  61. (`number`, default: `0.8`).
  62. #### `cropperOptions`
  63. Image Editor is using the excellent
  64. [Cropper.js](https://fengyuanchen.github.io/cropperjs/). `cropperOptions` will
  65. be directly passed to `Cropper` and thus can expect the same values as
  66. documented in their
  67. [README](https://github.com/fengyuanchen/cropperjs/blob/HEAD/README.md#options),
  68. with the addition of `croppedCanvasOptions`, which will be passed to
  69. [`getCroppedCanvas`](https://github.com/fengyuanchen/cropperjs/blob/HEAD/README.md#getcroppedcanvasoptions).
  70. #### `actions`
  71. Show action buttons (`Object` or `boolean`).
  72. If you you’d like to hide all actions, pass `false` to it. By default all the
  73. actions are visible. Or enable/disable them individually:
  74. ```js
  75. {
  76. revert: true,
  77. rotate: true,
  78. granularRotate: true,
  79. flip: true,
  80. zoomIn: true,
  81. zoomOut: true,
  82. cropSquare: true,
  83. cropWidescreen: true,
  84. cropWidescreenVertical: true,
  85. }
  86. ```
  87. #### `locale: {}`
  88. ```js
  89. export default {
  90. strings: {
  91. revert: 'Revert',
  92. rotate: 'Rotate',
  93. zoomIn: 'Zoom in',
  94. zoomOut: 'Zoom out',
  95. flipHorizontal: 'Flip horizontal',
  96. aspectRatioSquare: 'Crop square',
  97. aspectRatioLandscape: 'Crop landscape (16:9)',
  98. aspectRatioPortrait: 'Crop portrait (9:16)',
  99. },
  100. };
  101. ```
  102. ### Events
  103. :::info
  104. You can use [`on`](/docs/uppy#onevent-action) and
  105. [`once`](/docs/uppy#onceevent-action) to listen to these events.
  106. :::
  107. #### `file-editor:start`
  108. Emitted when `selectFile(file)` is called.
  109. ```js
  110. uppy.on('file-editor:start', (file) => {
  111. console.log(file);
  112. });
  113. ```
  114. #### `file-editor:complete`
  115. Emitted after `save(blob)` is called.
  116. ```js
  117. uppy.on('file-editor:complete', (updatedFile) => {
  118. console.log(updatedFile);
  119. });
  120. ```
  121. #### `file-editor:cancel`
  122. Emitted when `uninstall` is called or when the current image editing changes are
  123. discarded.
  124. ```js
  125. uppy.on('file-editor:cancel', (file) => {
  126. console.log(file);
  127. });
  128. ```