mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-08-16 20:11:24 +08:00
feat(ImageSource): resize method (#8678)
This commit is contained in:
27
nativescript-core/image-source/image-source-common.ts
Normal file
27
nativescript-core/image-source/image-source-common.ts
Normal file
@ -0,0 +1,27 @@
|
||||
export function getScaledDimensions(
|
||||
width: number,
|
||||
height: number,
|
||||
maxSize: number
|
||||
) {
|
||||
if (height >= width) {
|
||||
if (height <= maxSize) {
|
||||
// if image already smaller than the required height
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
return {
|
||||
width: Math.round((maxSize * width) / height),
|
||||
height: maxSize
|
||||
};
|
||||
}
|
||||
|
||||
if (width <= maxSize) {
|
||||
// if image already smaller than the required width
|
||||
return { width, height };
|
||||
}
|
||||
|
||||
return {
|
||||
width: maxSize,
|
||||
height: Math.round((maxSize * height) / width)
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user