Skip to content

Latest commit

 

History

History
168 lines (117 loc) · 6.31 KB

README.md

File metadata and controls

168 lines (117 loc) · 6.31 KB


Image Manipulator Plugin

@capacitor-community/image-manipulator

Capacitor community plugin to manipulate images (resize, compress, crop etc.)


Table of Contents

Maintainers

Maintainer GitHub Active
ryaa ryaa yes

About

This plugins allows to resize images.

Features:

  • supports getting image dimensions
  • supports resizing image
  • supports Android and iOS platforms

Plugin versions

Capacitor version Plugin version
6.x 6.x

Supported Platforms

  • iOS
  • Android

Install

npm install @capacitor-community/image-manipulator
npx cap sync

API

getDimensions(...)

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(...)

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


Interfaces

GetDimensionsOptions

Prop Type Description Since
imagePath string The path to the image to get its dimensions. 6.0.0

ResizeOptions

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

Usage

Resize image

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);

Resize image

import { ImageManipulator } from '@capacitor-community/image-manipulator';

const options: GetDimensionsOptions = {
  imagePath: 'path/to/image.jpg'
};
const result = await ImageManipulator.getDimensions(options);