feat: metadataSync (#137)

This commit is contained in:
Vasilii A 2025-06-28 14:40:37 +03:00 committed by GitHub
parent 2e8fcc3e92
commit 829ec1ad17
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 18 additions and 0 deletions

View File

@ -37,6 +37,13 @@ test('should be able to get exif from jpg', async (t) => {
t.is(metadata.format, 'jpeg')
})
test('should be able to get metadata from jpg - sync', (t) => {
const decoder = new Transformer(JPEG)
const metadata = decoder.metadataSync()
t.is(metadata.width, 1024)
t.is(metadata.height, 678)
})
test('should be able to encode into webp', async (t) => {
const decoder = new Transformer(PNG)
await t.notThrowsAsync(() => decoder.webp(75))

View File

@ -781,6 +781,16 @@ impl Transformer {
)
}
#[napi]
pub fn metadata_sync(&mut self, env: Env, with_exif: Option<bool>) -> Result<Metadata> {
let mut task = MetadataTask {
dynamic_image: self.dynamic_image.clone(),
with_exif: with_exif.unwrap_or(false),
};
let output = task.compute()?;
task.resolve(env, output)
}
#[napi]
/// Rotate with exif orientation
/// If the orientation param is not null,

View File

@ -79,6 +79,7 @@ writeFileSync(
```ts
metadata(withExif?: boolean | undefined | null, signal?: AbortSignal | undefined | null): Promise<Metadata>
metadataSync(withExif?: boolean | undefined | null): Metadata
export interface Metadata {
width: number