@@ -60,8 +60,8 @@ import transformImage from '@shellophobia/transform-image-js';
6060function handleUpload (e ){
6161 const file = e .target .files [0 ];
6262 // The library will add a property `transformImageJS` on window once you import it
63- const transformImage = new transformImageJS.TransformImage ({maxHeight : 500 , maxWidth : 500 , quality : 0.9 });
64- transformImage .resizeImage (file).then (res => {
63+ const transformImage = new transformImageJS.TransformImage ({});
64+ transformImage .resizeImage (file, {maxHeight : 500 , maxWidth : 500 , quality : 0.9 } ).then (res => {
6565 // The response returns an object that has the output blob in output attribute and has metadata for image sizes before and after transformation
6666 console .log (res);
6767 }).catch (err => {
@@ -72,9 +72,9 @@ function handleUpload(e){
7272// using async function
7373async function handleUpload (e ) {
7474 const file = e .target .files [0 ];
75- const transformImage = new transformImageJS.TransformImage ({maxHeight : 500 , maxWidth : 500 , quality : 0.9 });
75+ const transformImage = new transformImageJS.TransformImage ({});
7676 try {
77- const res = await transformImage .resizeImage (file);
77+ const res = await transformImage .resizeImage (file, {maxHeight : 500 , maxWidth : 500 , quality : 0.9 } );
7878 console .log (res);
7979 } catch (e) {
8080 // handle error
@@ -90,9 +90,9 @@ import transformImage from "@shellophobia/transform-image-js";
9090const handleUpload = async (e ) => {
9191 const file = e .target .files [0 ];
9292 console .log (file);
93- const transformImage = new transformImage ({maxHeight : 500 , maxWidth : 500 , quality : 0.9 });
93+ const transformImage = new transformImage ({});
9494 try {
95- const res = await transformImage .resizeImage (file);
95+ const res = await transformImage .resizeImage (file, {maxHeight : 500 , maxWidth : 500 , quality : 0.9 } );
9696 console .log (res);
9797 } catch (e) {
9898 console .log (e);
@@ -117,28 +117,33 @@ Following options can be passed during initialization of transformImage that ret
117117
118118#### ` transformImage(options) `
119119
120- | Name | Type | Description | Default |
121- | ------------------| ----------| ------------------------------------------------------------------------------------------------------------| ------------------------|
122- | sizeLimit | int | Byte size limit of the output | 16777216 // 16MB |
123- | maxWidth | int | Max width of the output | 500 |
124- | maxHeight | int | Max height of the output | 500 |
125- | quality | float | A Number between 0 and 1 indicating the image quality to use for image formats that use lossy compression | 0.92 |
126- | base64OutputType | bool | Return base64 output string in response | false |
127- | blobOutputType | bool | Return blob output in response | true |
128- | allowedFileTypes | [ ] string | Array of allowed file types for uploaded file | [ "jpg", "png", "jpeg"] |
120+ | Name | Type | Description | Default |
121+ | ------------------| ----------| ----------------------------------------------------------------------| ------------------------|
122+ | sizeLimit | int | the byte size limit for the input file/blob | 16* 1024* 1024 = 16MB |
123+ | outputType | enum | defines the output object format. Allowed values :- blob/base64/file | blob |
124+ | allowedFileTypes | [ ] string | allowed types for the input file/blob e.g. PNG, JPEG, JPG | [ "jpg", "png", "jpeg"] |
129125
130126
131127### Methods
132128
133- ### ` resizeImage(imageFile) => {Promise} `
129+ ### ` resizeImage(imageFile, options, fileName ) => {Promise} `
134130
135131#### Description:
136- Resize an image file with the configuration provided in the initialization options
132+ Resize an image file
137133
138134#### Parameters:
139- | Name | Type | Description |
140- | ---------------| ------| --------------------------|
141- | imageFile | file | The image file to resize |
135+ | Name | Type | Description | Required | Default |
136+ | ----------| -----------| ---------------------------------------------------------------------------------------------| ----------| ---------|
137+ | image | File/Blob | File object / Blob to be resized | Yes | N/A |
138+ | options | Object | Additional options described below. The values can also override the TransformImage options | No | {} |
139+ | fileName | string | Name of the file if outputType is file (Optional) | No | "" |
140+
141+ ##### Options
142+ | Name | Type | Description | Default |
143+ | -----------| -------| -------------------------------------------------------------------| ---------|
144+ | maxWidth | int | the max width for the file in px | 500 |
145+ | maxHeight | int | the max height for the file in px | 500 |
146+ | quality | float | a value between 0 and 1 to denote the quality of the output image | 0.9 |
142147
143148#### Returns:
144149Promise that resolves to the output object
0 commit comments