Preset Mode
This plugin provides some commonly used preset modes for quick use in daily business scenarios.
Type Declarations
ts
/**
* Preset options for component props
* @since 0.4.0
*/
export interface PresetModeOptions {
mode?: SupportedPresetMode
width?: number
height?: number
}
/**
* Preset Modes Supported by Components
*/
export type SupportedPresetMode =
// Specifies the size of the cropped result
| 'fixedSize'
// Generate a round cropping result
| 'round'
Notices
- The preset mode only provides some simplified configurations. For example, obtaining the round cropping result originally requires cumbersome operations. Using the preset mode is out of the box, but some options that should be passed in still need to be passed in
options, you can refer to the source code of live demos. - When using the preset mode, the "cropping area" and "cropping result" will keep the same size, that is,
presetMode.widthandpresetMode.heightspecified in the preset mode will override Thewidthandheightpassed in bygetDataURLand other get result APIs. - When specifying
presetMode.widthandpresetMode.height, please pay attention to whether the aspect ratio is consistent withoptions.aspectRatio, if not, you may not get the desired result presetMode.modeonly accepts the values mentioned in theSupportedPresetModetype, passing in other values will not work
Fixed Size Mode
The size of the cropping area can be fixed, and the cropping result is as large as the cropping area (in this case, the user can be prohibited from modifying the size of the cropping area).
Click to view: Live Demo
- Instructions:
- Specify
modeofpresetModeasfixedSize - Specify
widthandheightofpresetModeto be the desired size - Set
dragModeofoptionstomoveto prevent the crop box from being canceled - Set
cropBoxResizableofoptionstofalseto turn off crop box resizing - Specify the aspectRatio ratio of
optionsas a ratio ofwidth / height
- Example:
html
<template>
<vue-picture-cropper
:boxStyle="{
width: '100%',
height: '100%',
backgroundColor: '#f8f8f8',
margin: 'auto',
}"
:img="pic"
:options="{
viewMode: 1,
dragMode: 'move',
aspectRatio: 1,
cropBoxResizable: false,
}"
:presetMode="{
mode: 'fixedSize',
width: 100,
height: 100,
}"
/>
</template>
Round Mode
If business scenarios such as user uploading avatars need to be cropped into a circular image, you can use this mode to obtain a circular PNG image (in this mode, the cropping result is always a .png image).
This mode also fixes the size of the cropping area, and the cropping result is as large as the cropping area (in this case, the user can be prohibited from modifying the size of the cropping area).
Click to view: Live Demo
- Instructions:
- Specify the
modeofpresetModeasround - Specify the
widthandheightofpresetModeas the desired size, the two values need to be the same - Set
dragModeofoptionstomoveto prevent the crop box from being canceled - Set
cropBoxResizableofoptionstofalseto turn off crop box resizing - Specify aspectRatio ratio of
optionsto1
- Example:
html
<template>
<vue-picture-cropper
:boxStyle="{
width: '100%',
height: '100%',
backgroundColor: '#f8f8f8',
margin: 'auto',
}"
:img="pic"
:options="{
viewMode: 1,
dragMode: 'move',
aspectRatio: 1,
cropBoxResizable: false,
}"
:presetMode="{
mode: 'round',
width: 100,
height: 100,
}"
/>
</template>