一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
40 行
1019 B
TypeScript
40 行
1019 B
TypeScript
import { fileUriToPath } from '@joplin/utils/url';
|
|
import { Image as NativeImage, Platform } from 'react-native';
|
|
import fileToImage from './fileToImage.web';
|
|
|
|
interface ImageDimensions {
|
|
width: number;
|
|
height: number;
|
|
}
|
|
|
|
const getImageDimensions = async (uri: string): Promise<ImageDimensions> => {
|
|
if (uri.startsWith('/')) {
|
|
uri = `file://${uri}`;
|
|
}
|
|
|
|
// On web, image files are stored using the Origin Private File System and need special
|
|
// handling.
|
|
const isFileUrl = uri.startsWith('file://');
|
|
if (Platform.OS === 'web' && isFileUrl) {
|
|
const path = isFileUrl ? fileUriToPath(uri) : uri;
|
|
const image = await fileToImage(path);
|
|
const size = { width: image.image.width, height: image.image.height };
|
|
image.free();
|
|
return size;
|
|
}
|
|
|
|
return new Promise((resolve, reject) => {
|
|
NativeImage.getSize(
|
|
uri,
|
|
(width: number, height: number) => {
|
|
resolve({ width: width, height: height });
|
|
},
|
|
(error: unknown) => {
|
|
reject(error);
|
|
},
|
|
);
|
|
});
|
|
};
|
|
|
|
export default getImageDimensions;
|