-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: change description in image files
- Loading branch information
Showing
8 changed files
with
114 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import fs from "fs/promises"; | ||
import path from "path"; | ||
import { updateImageDescription } from "./exiftool"; | ||
import { load } from "exifreader"; | ||
|
||
describe("exiftool", () => { | ||
const imageFile = path.resolve( | ||
__dirname, | ||
"../../test_resources/test_DSC07588_with_description.jpg", | ||
); | ||
let tempFile: string; | ||
|
||
beforeEach(async () => { | ||
const { temporaryFile } = await import("tempy"); | ||
tempFile = temporaryFile({ name: "exiftool_test" }); | ||
await fs.copyFile(imageFile, tempFile); | ||
}); | ||
|
||
it("behaves", async () => { | ||
await updateImageDescription(tempFile, "new description"); | ||
const tags = await load(tempFile, { expanded: true }); | ||
expect(tags.exif?.ImageDescription).toEqual("new description"); | ||
}); | ||
|
||
afterEach(async () => { | ||
await fs.unlink(tempFile); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { execFile } from "promisify-child-process"; | ||
import fs from "fs/promises"; | ||
|
||
export const updateImageDescription = async ( | ||
file: string, | ||
description: string, | ||
) => { | ||
const { temporaryWrite, temporaryFile } = await import("tempy"); | ||
const argFile = await temporaryWrite(description, { name: "args" }); | ||
const newFile = temporaryFile({ name: "newFile" }); | ||
await execFile("exiftool", [ | ||
`-mwg:Description<${argFile}`, | ||
file, | ||
"-o", | ||
newFile, | ||
]); | ||
await fs.unlink(argFile); | ||
await fs.copyFile(newFile, file); | ||
await fs.unlink(newFile); | ||
}; |