Index F Number instead of Aperture
Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
parent
8557c298d0
commit
3fedffe21b
8 changed files with 32 additions and 13 deletions
|
@ -27,7 +27,7 @@ type Photo struct {
|
|||
PhotoAltitude int
|
||||
PhotoFocalLength int
|
||||
PhotoIso int
|
||||
PhotoAperture float64
|
||||
PhotoFNumber float64
|
||||
PhotoExposure string
|
||||
PhotoViews uint
|
||||
Camera *Camera
|
||||
|
|
|
@ -28,6 +28,7 @@ type Exif struct {
|
|||
FocalLength int
|
||||
Exposure string
|
||||
Aperture float64
|
||||
FNumber float64
|
||||
Iso int
|
||||
Lat float64
|
||||
Long float64
|
||||
|
@ -150,6 +151,17 @@ func (m *MediaFile) Exif() (result *Exif, err error) {
|
|||
m.exifData.Exposure = value
|
||||
}
|
||||
|
||||
if value, ok := tags["FNumber"]; ok {
|
||||
values := strings.Split(value, "/")
|
||||
|
||||
if len(values) == 2 && values[1] != "0" && values[1] != "" {
|
||||
number, _ := strconv.ParseFloat(values[0], 64)
|
||||
denom, _ := strconv.ParseFloat(values[1], 64)
|
||||
|
||||
m.exifData.FNumber = math.Round((number/denom)*1000) / 1000
|
||||
}
|
||||
}
|
||||
|
||||
if value, ok := tags["ApertureValue"]; ok {
|
||||
values := strings.Split(value, "/")
|
||||
|
||||
|
|
|
@ -35,6 +35,7 @@ func TestMediaFile_Exif_JPEG(t *testing.T) {
|
|||
assert.Equal(t, 111, info.FocalLength)
|
||||
assert.Equal(t, "1/640", info.Exposure)
|
||||
assert.Equal(t, 6.644, info.Aperture)
|
||||
assert.Equal(t, 10.0, info.FNumber)
|
||||
assert.Equal(t, 200, info.Iso)
|
||||
assert.Equal(t, -33.45347, info.Lat)
|
||||
assert.Equal(t, 25.764645, info.Long)
|
||||
|
@ -69,6 +70,7 @@ func TestMediaFile_Exif_JPEG(t *testing.T) {
|
|||
assert.Equal(t, 100, info.FocalLength)
|
||||
assert.Equal(t, "1/250", info.Exposure)
|
||||
assert.Equal(t, 6.644, info.Aperture)
|
||||
assert.Equal(t, 10.0, info.FNumber)
|
||||
assert.Equal(t, 200, info.Iso)
|
||||
assert.Equal(t, 0, info.Altitude)
|
||||
assert.Equal(t, 2048, info.Width)
|
||||
|
|
|
@ -156,11 +156,11 @@ func (i *Indexer) indexMediaFile(mediaFile *MediaFile) string {
|
|||
}
|
||||
}
|
||||
|
||||
// Set Camera, Lens, Focal Length and Aperture
|
||||
// Set Camera, Lens, Focal Length and F Number
|
||||
photo.Camera = models.NewCamera(mediaFile.CameraModel(), mediaFile.CameraMake()).FirstOrCreate(i.db)
|
||||
photo.Lens = models.NewLens(mediaFile.LensModel(), mediaFile.LensMake()).FirstOrCreate(i.db)
|
||||
photo.PhotoFocalLength = mediaFile.FocalLength()
|
||||
photo.PhotoAperture = mediaFile.Aperture()
|
||||
photo.PhotoFNumber = mediaFile.FNumber()
|
||||
photo.PhotoIso = mediaFile.Iso()
|
||||
photo.PhotoExposure = mediaFile.Exposure()
|
||||
}
|
||||
|
|
|
@ -156,14 +156,14 @@ func (m *MediaFile) FocalLength() int {
|
|||
return result
|
||||
}
|
||||
|
||||
// Aperture returns the aperture with which the media file was created.
|
||||
func (m *MediaFile) Aperture() float64 {
|
||||
// FNumber returns the F number with which the media file was created.
|
||||
func (m *MediaFile) FNumber() float64 {
|
||||
info, err := m.Exif()
|
||||
|
||||
var result float64
|
||||
|
||||
if err == nil {
|
||||
result = info.Aperture
|
||||
result = info.FNumber
|
||||
}
|
||||
|
||||
return result
|
||||
|
|
|
@ -136,20 +136,20 @@ func TestMediaFile_FocalLength(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestMediaFile_Aperture(t *testing.T) {
|
||||
func TestMediaFile_FNumber(t *testing.T) {
|
||||
t.Run("/cat_brown.jpg", func(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/cat_brown.jpg")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 2.275, mediaFile.Aperture())
|
||||
assert.Equal(t, 2.2, mediaFile.FNumber())
|
||||
})
|
||||
t.Run("/elephants.jpg", func(t *testing.T) {
|
||||
conf := config.TestConfig()
|
||||
|
||||
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/elephants.jpg")
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, 6.644, mediaFile.Aperture())
|
||||
assert.Equal(t, 10.0, mediaFile.FNumber())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -171,11 +171,11 @@ func (s *Search) Photos(form forms.PhotoSearchForm) (results []PhotoSearchResult
|
|||
}
|
||||
|
||||
if form.Fmin > 0 {
|
||||
q = q.Where("photos.photo_aperture >= ?", form.Fmin)
|
||||
q = q.Where("photos.photo_f_number >= ?", form.Fmin)
|
||||
}
|
||||
|
||||
if form.Fmax > 0 {
|
||||
q = q.Where("photos.photo_aperture <= ?", form.Fmax)
|
||||
q = q.Where("photos.photo_f_number <= ?", form.Fmax)
|
||||
}
|
||||
|
||||
if form.Dist == 0 {
|
||||
|
|
|
@ -20,12 +20,17 @@ type PhotoSearchResult struct {
|
|||
PhotoKeywords string
|
||||
PhotoColors string
|
||||
PhotoColor string
|
||||
PhotoLat float64
|
||||
PhotoLong float64
|
||||
PhotoFavorite bool
|
||||
PhotoPrivate bool
|
||||
PhotoSensitive bool
|
||||
PhotoStory bool
|
||||
PhotoLat float64
|
||||
PhotoLong float64
|
||||
PhotoAltitude int
|
||||
PhotoFocalLength int
|
||||
PhotoIso int
|
||||
PhotoFNumber float64
|
||||
PhotoExposure string
|
||||
|
||||
// Camera
|
||||
CameraID uint
|
||||
|
|
Loading…
Reference in a new issue