Exif WhiteBalance

hugo exif tags doesn’t have a tag for WhiteBalance. I don’t know which library it is using to process exif on page but it is not returning any value for following code:

            {{ if .Tags.WhiteBalance }}
                <div class="exif">
                    <i class="fa fa-lightbulb"></i> White Balance: 
                    {{ .Tags.WhiteBalance }}
                </div>
            {{ end }}

I have checked with exifTool, data for White Balance is there. When I output all .Tags it doesn’t have Tag for WhiteBalance. So just curious if it is there in the library that hugo is using or am I missing something.

All other tags that I need are working properly but lot of tags are missing, very basic ones.

Add this to your site configuration file:

[imaging.exif]
includeFields = ".*"

See https://gohugo.io/content-management/image-processing/#image-processing-config

oh, I read it and missed it, sorry, let me check it…
thanks for the early reply.

other tags are working now but WhiteBalance is still not working. Do I need to format the output of the tag? It has a numeric value, but it is not even displaying it.

I changed code to this:

            {{ if .Tags.WhiteBalance }}
                <div class="exif">
                    <i class="fa fa-lightbulb"></i> White Balance: 
                    {{ .Tags.WhiteBalance }} {{ .Format "." }}
                </div>
            {{ end }}

all most all other tags are working individually, but whitebalance displays only as a part of the display all tags but not individually. when i display all tags it correctly shows 16 as value but individually it returns no value. strange.

What do you see when you do this?

{{ $image := resources.Get "foo" }}
{{ with $image.Exif }}
  {{ range $k, $v := .Tags }}
    {{ $k }} = {{ $v }}<br>
  {{ end }}
{{ end }}

yes, i tried that and output is as expected:

Date: 2021-04-16 18:11:07 +0000 UTC Lat/Long: 0/0 Tags: TAG: ApertureValue: 2.27 TAG: BrightnessValue: 4.26 TAG: ColorSpace: 1 TAG: ComponentsConfiguration: TAG: DateTime: 2021-04-16 18:11:07 +0000 UTC TAG: DateTimeDigitized: 2021-04-16 18:11:07 +0000 UTC TAG: DateTimeOriginal: 2021-04-16 18:11:07 +0000 UTC TAG: ExifIFDPointer: 193 TAG: ExifVersion: 0220 TAG: ExposureMode: 0
TAG: ExposureProgram: 0 TAG: ExposureTime: 1/50 TAG: FNumber: 2.2 TAG: Flash: 16 TAG: FlashpixVersion: 0100 TAG: FocalLength: 6.605 TAG: FocalLengthIn35mmFilm: 7 TAG:
GPSInfoIFDPointer: 674 TAG: ISOSpeedRatings: 58 TAG: InteroperabilityIFDPointer: 644 TAG: InteroperabilityIndex: R98 TAG: Make: vivo TAG: MeteringMode: 2 TAG: Model: vivo 1906 TAG:
PixelXDimension: 3120 TAG: PixelYDimension: 4160 TAG: ResolutionUnit: 2 TAG: SceneCaptureType: 0 TAG: SceneType: TAG: SensingMethod: 0 TAG: ShutterSpeedValue: 5.643 TAG: Software: Hypocam TAG:
SubSecTime: 137022 TAG: SubSecTimeDigitized: 137022 TAG: SubSecTimeOriginal: 137022 TAG: ThumbJPEGInterchangeFormat: 774 TAG: ThumbJPEGInterchangeFormatLength: 7311 TAG: WhiteBalance: 0
TAG: XResolution: 72 TAG: YCbCrPositioning: 1 TAG: YResolution: 72

but WhiteBalance tag is not displaying individually.

WhiteBalance: 0

The zero is an integer, not a string. You can verify with:

{{ printf "%T" $image.Exif.Tags.WhiteBalance }}

So this:

{{ if $image.Exif.Tags.WhiteBalance }}
  DO SOMETHING
{{ else }}
  DO NOT DO ANYTHING
{{ end }}

Produces:

DO NOT DO ANYTHING

When using if or with zero, false, and the empty string are all falsey.

1 Like

that is happening with all .Tags that return boolean values. like ExposureMode is also not working as it returns integer. need to change code than. thanks for your help, not familiar with hu/go code that much.

You can use isset to see if a value has been set, even if it falsey.

{{ if isset $image.Exif.Tags "WhiteBalance" }}
  DO SOMETHING
{{ else }}
  DO NOT DO ANYTHING
{{ end }}

Produces:

DO SOMETHING

regardless of what the value is.

one more thing, it returns 0 and 1 as values. I want to convert 0: Auto and 1: Manual for display. what would be the easiest way to do that? edit existing exif.html shortcode template?

ok, working now. thanks for you help. just need to change boolean values to text for display now. is there any tutorial guide for that which i can follow.

Thank you.

{{ $whiteBalance := "Auto" }}
{{ if $image.Exif.Tags.WhiteBalance }}
  {{ $whiteBalance = "Manual" }}
{{ end }}

There are several tutorials available. Some that come to mind are:

The last one is a bit dated, but still quite valuable.

1 Like

thanks for the links, i am using it for a while so familiar with basic settings. but if statements are not working for me somehow.

i have following code:

            {{ if isset .Tags "ExposureMode" }}
                <div class="exif">
                    <i class="fa fa-lightbulb"></i> Exposure Mode: {{ .Tags.ExposureMode}}
                    {{ if $ExposureMode := "0" }} Auto
                    {{ else if $ExposureMode := "1" }} Manual
                    {{ else }} Auto bracket
                  {{ end }}
                </div>
                {{ else }}
                {{ end }}

which gives me output like:

0 Auto
1 Auto
2 Auto

instead of

0 Auto
1 Manual
2 Auto Bracket

following tut here: Conditionals | Hugo | Mike Dane

are there any good cheatsheets or manuals for hugo coding so that i can get familiar with it, printable pdf would be handy for reference.

You’re assigning (:=), not testing for equality.

ok, thanks it is working now with following code:

            {{ if isset .Tags "ExposureMode" }}
                <div class="exif">
                    <i class="fa fa-lightbulb"></i> Exposure Mode: {{ .Tags.ExposureMode}}
                    {{ if eq .Tags.ExposureMode 0 }} Auto
                    {{ else if eq .Tags.ExposureMode 1 }} Manual
                    {{ else }} Auto bracket
                  {{ end }}
                </div>
                {{ else }}
                {{ end }}

is there a more efficient way to do this?

thanks for your reply.

Firstly, why? Do you think that build time is long because of this?
Secondly, you could slim it down a bit with with:

{{with .Tags.ExposureMode}} 
{{ if eq . 1}} Manual {{/* ExposureMode eq 1 */}}
{{ else}} Auto bracket {{/* ExposureMode neither 0 nor 1 */}}
{{end}}
{{ else}} Auto {{/* ExposureMode 0 */}}
{{end}}

with is true in this context for all values not equal zero, so you only have to test dot for 1 in the if(dot is set to .Tags.ExposureMode by the with). The else inside the if is always true if ExposureMode is neither 1 nor 0, and finally the last else is true if ExposureMode is 0 (because then with is false).
If you only have the values 0, 1 and 2, you could probably use a slice like so

{{ $modes := slice "Auto" "Manual" "Auto bracket"}}
{ {if isset .Tags "ExposureMode" }} 
...
{{index $modes .Tags.ExposureMode}}
...

I hope :wink:
And there might be other ways. But I’m still wondering if this piece of code merits optimisation.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.