@capacitor-community/image-manipulator
Capacitor community plugin to manipulate images (resize, compress, crop etc.)
Maintainer | GitHub | Active |
---|---|---|
ryaa | ryaa | yes |
This plugins allows to resize images.
Features:
- supports getting image dimensions
- supports resizing image
- supports Android and iOS platforms
Capacitor version | Plugin version |
---|---|
6.x | 6.x |
- iOS
- Android
npm install @capacitor-community/image-manipulator
npx cap sync
getDimensions(options: GetDimensionsOptions) => Promise<{ width: number; height: number; }>
Get dimensions of an image (width and height)
Param | Type | Description |
---|---|---|
options |
GetDimensionsOptions |
options to get dimensions of an image |
Returns: Promise<{ width: number; height: number; }>
Since: 6.0.0
resize(options: ResizeOptions) => Promise<{ originalWidth: number; originalHeight: number; resizedWidth: number; resizedHeight: number; imagePath: string; webPath: string; resized: boolean; }>
Method to resize an image If the image width and height are less than the provided maxWidth and maxHeight, the image will not be resized.
Param | Type | Description |
---|---|---|
options |
ResizeOptions |
Options to resize an image |
Returns: Promise<{ originalWidth: number; originalHeight: number; resizedWidth: number; resizedHeight: number; imagePath: string; webPath: string; resized: boolean; }>
Since: 6.0.0
Prop | Type | Description | Since |
---|---|---|---|
imagePath |
string |
The path to the image to get its dimensions. | 6.0.0 |
Prop | Type | Description | Since |
---|---|---|---|
imagePath |
string |
The path to the image to resize. | 6.0.0 |
folderName |
string |
The name of the folder to store the resized images (optional, defaults to 'ResizedImages' if not provided). | 6.0.0 |
fileName |
string |
The name of the resized file without extension (optional, timestamp as name if not provided). | 6.0.0 |
quality |
number |
The resized image quality (optional, defaults to 85 if not provided). | 6.0.0 |
maxWidth |
number |
The max width of the resized image (optional, but at least either height or width must be provided). | 6.0.0 |
maxHeight |
number |
The max height of the resized image (optional, but at least either width or height must be provided). | 6.0.0 |
fixRotation |
boolean |
Fix the rotation of the image based on EXIF metadata (optional, defaults to false if not provided). | 6.0.0 |
import { ImageManipulator } from '@capacitor-community/image-manipulator';
const options: ImageResizeOptions = {
imagePath: 'path/to/image.jpg',
maxWidth: 300,
maxHeight: 300,
quality: 85,
folderName: 'ResizedImages',
fileName: 'resized',
fixRotation: true
};
const result = await ImageManipulator.resize(options);
import { ImageManipulator } from '@capacitor-community/image-manipulator';
const options: GetDimensionsOptions = {
imagePath: 'path/to/image.jpg'
};
const result = await ImageManipulator.getDimensions(options);