@@ -60,8 +60,8 @@ import transformImage from '@shellophobia/transform-image-js';
60
60
function handleUpload (e ){
61
61
const file = e .target .files [0 ];
62
62
// 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 => {
65
65
// The response returns an object that has the output blob in output attribute and has metadata for image sizes before and after transformation
66
66
console .log (res);
67
67
}).catch (err => {
@@ -72,9 +72,9 @@ function handleUpload(e){
72
72
// using async function
73
73
async function handleUpload (e ) {
74
74
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 ({});
76
76
try {
77
- const res = await transformImage .resizeImage (file);
77
+ const res = await transformImage .resizeImage (file, {maxHeight : 500 , maxWidth : 500 , quality : 0.9 } );
78
78
console .log (res);
79
79
} catch (e) {
80
80
// handle error
@@ -90,9 +90,9 @@ import transformImage from "@shellophobia/transform-image-js";
90
90
const handleUpload = async (e ) => {
91
91
const file = e .target .files [0 ];
92
92
console .log (file);
93
- const transformImage = new transformImage ({maxHeight : 500 , maxWidth : 500 , quality : 0.9 });
93
+ const transformImage = new transformImage ({});
94
94
try {
95
- const res = await transformImage .resizeImage (file);
95
+ const res = await transformImage .resizeImage (file, {maxHeight : 500 , maxWidth : 500 , quality : 0.9 } );
96
96
console .log (res);
97
97
} catch (e) {
98
98
console .log (e);
@@ -117,28 +117,33 @@ Following options can be passed during initialization of transformImage that ret
117
117
118
118
#### ` transformImage(options) `
119
119
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"] |
129
125
130
126
131
127
### Methods
132
128
133
- ### ` resizeImage(imageFile) => {Promise} `
129
+ ### ` resizeImage(imageFile, options, fileName ) => {Promise} `
134
130
135
131
#### Description:
136
- Resize an image file with the configuration provided in the initialization options
132
+ Resize an image file
137
133
138
134
#### 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 |
142
147
143
148
#### Returns:
144
149
Promise that resolves to the output object
0 commit comments