react-native-compressor: [Error: width and height must be > 0] On image compression
Current behavior
When trying to compress an image from URI or base64 an error is thrown.
[Error: width and height must be > 0]
Expected behavior
To be able to compress an image using base64 and throw a more elaborate error.
Platform
- Android
- iOS (Not tested)
Code
This will throw the error
try {
const compressedSource = await compressFile(
CompressFileType.IMAGE,
'https://picsum.photos/500'
);
console.log(compressedSource);
} catch (error) {
console.error(error);
}
And this is where the compression is handled
import { Image, Video, Audio } from 'react-native-compressor';
import { CompressFileType } from '../../enums/CompressFileType';
const compressFile = async (fileType: CompressFileType, value: string) => {
console.log('Compressing ' + fileType + ' with value ' + value);
switch (fileType) {
case CompressFileType.IMAGE:
console.log('IMAGE');
const imageResult = await Image.compress(value, {
compressionMethod: 'auto',
// input: 'base64',
maxHeight: 50,
maxWidth: 50,
});
return imageResult;
case CompressFileType.VIDEO:
console.log('VIDEO');
const videoResult = await Video.compress(value, {
compressionMethod: 'auto',
});
return videoResult;
case CompressFileType.AUDIO:
console.log('AUDIO');
const audioResult = await Audio.compress(value, {
quality: 'medium',
});
return audioResult;
default:
throw new Error(`Unknown file type '${fileType}'`);
}
};
export { compressFile };
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 3
- Comments: 17 (3 by maintainers)
This is what i require.