2
0
mirror of https://github.com/thumbsup/thumbsup synced 2024-11-03 15:40:14 +00:00

Read the caption from all standard EXIF/IPTC/XMP tags (issue #24)

This commit is contained in:
Romain 2017-03-08 21:40:09 +11:00
parent 4ccb10baba
commit 449ee0b180
2 changed files with 26 additions and 23 deletions

View File

@ -32,9 +32,12 @@ function exifDate (file) {
}
function caption (file) {
const desc = file.meta.EXIF ? file.meta.EXIF['ImageDescription'] : null
const caption = file.meta.IPTC ? file.meta.IPTC['Caption-Abstract'] : null
return desc || caption
return tagValue(file, 'EXIF', 'ImageDescription') ||
tagValue(file, 'IPTC', 'Caption-Abstract') ||
tagValue(file, 'IPTC', 'Headline') ||
tagValue(file, 'XMP', 'Description') ||
tagValue(file, 'XMP', 'Title') ||
tagValue(file, 'XMP', 'Label')
}
function animated (file) {
@ -43,4 +46,9 @@ function animated (file) {
return false
}
function tagValue (file, type, name) {
if (!file.meta[type]) return null
return file.meta[type][name]
}
module.exports = Media

View File

@ -53,26 +53,21 @@ describe('Media', function () {
})
describe('caption', function () {
it('uses the EXIF caption if present', function () {
const file = fixtures.file()
file.meta.EXIF['ImageDescription'] = 'some caption'
const media = new Media(file)
should(media.caption).eql('some caption')
})
it('uses the IPTC caption if present', function () {
const file = fixtures.file()
file.meta.IPTC['Caption-Abstract'] = 'some caption'
const media = new Media(file)
should(media.caption).eql('some caption')
})
it('uses the EXIF caption if both EXIF and IPTC exist', function () {
const file = fixtures.file()
file.meta.EXIF['ImageDescription'] = 'exif caption'
file.meta.IPTC['Caption-Abstract'] = 'iptc caption'
const media = new Media(file)
should(media.caption).eql('exif caption')
it('is read from all standard EXIF/IPTC/XMP tags', function () {
const tags = [
{ type: 'EXIF', tag: 'ImageDescription' },
{ type: 'IPTC', tag: 'Caption-Abstract' },
{ type: 'IPTC', tag: 'Headline' },
{ type: 'XMP', tag: 'Description' },
{ type: 'XMP', tag: 'Title' },
{ type: 'XMP', tag: 'Label' }
]
tags.forEach(t => {
const file = fixtures.file()
file.meta[t.type][t.tag] = 'some caption'
const media = new Media(file)
should(media.caption).eql('some caption')
})
})
})
})