mirror of
https://github.com/Brooooooklyn/Image.git
synced 2025-12-08 18:36:03 +00:00
feat: metadataSync (#137)
This commit is contained in:
parent
2e8fcc3e92
commit
829ec1ad17
@ -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))
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user