I'm trying to resize the uploaded image to 16:9. I've been trying all day and this is the best I've done so far.
const resizeResult = await manipulateAsync(
uploadResult.uri,
[
{
resize:
uploadResult.width > uploadResult.height
? { height: 900 }
: { width: 1600 },
},
{
crop: {
width: 1600,
height: 900,
originX:
uploadResult.width > uploadResult.height
? (uploadResult.height - uploadResult.width) / 2
: (uploadResult.width - uploadResult.height) / 2,
originY: 0,
},
},
],
{ compress: 0.7, format: SaveFormat.JPEG }
);
Unfortunately, this resizes/crops the 1800x1200 image to 1350x900, not 1600x900.
I think you just have to calculate and cap the size of the image using its aspect ratio.
const ratio = uploadResult.width / uploadResult.height;
let newWidth = ratio * 900;
let newHeight = 900;
if (ratio > 0) {
newWidth = 1600;
newHeight = 1600 / ratio;
}
const resizeResult = await manipulateAsync(
uploadResult.uri,
[
{
resize: { height: newHeight, width: newWidth }
}
],
{ compress: 0.7, format: SaveFormat.JPEG }
);