xyproto / wallutils

:city_sunset: Utilities for handling monitors, resolutions, wallpapers and timed wallpapers
BSD 3-Clause "New" or "Revised" License
463 stars 17 forks source link

Support macOS dynamic wallpapers (HEIF format with metadata and the `.heic` extension) #23

Closed jokeyrhyme closed 2 years ago

jokeyrhyme commented 3 years ago

Howdie, thanks so much for sharing this

I was looking around for timed wallpaper sets, and came across https://dynamicwallpaper.club/ which is specifically for the Dynamic Wallpapers functionality in macOS

It looks like these are HEIC or HEIF format files, which do open in GIMP, but aren't a ZIP or compressed TAR like I was thinking at at first

Anyhow, I was wondering if you already knew how to us these with settimed, or if you'd consider adding support for this file format? Being able to access themes from other popular platforms (:sigh:) could be very useful for some

Cheers!

xyproto commented 2 years ago

Hi, thanks for writing the feature request! Being able to use macOS dynamic wallpapers is a good idea!

eddsalkield commented 2 years ago

I'd be up for seeing this as well, so I've taken a look into the .heic file format. It's a container file format which contains several images, with some metadata describing the azimuth and elevation of the sun for each image. This allows the timed wallpaper to synchronise with sunrise and sunset based on your current location, and show photographs relevant to the season (e.g. no sun-directly-overhead images during the middle of winter).

You can inspect this metadata with the following steps:

exiftool wallpaper.heic

Under the key "Solar" there's a base64 encoded plist file. You can decode this with:

echo "[Base64 string]" | base64 -d - | plistutil

The output is some XML containing a list of dicts providing azimuth, elevation, and optionally light/dark mode for each photo, identified by a sequence number. This article goes into more details.

Perhaps the way support this is to firstly extend the stw format to allow azimuth and elevation information per photograph, and then write a converter from .heic to stw. This could happen implicitly so that .heic files can be opened natively. I suppose ideally stw could be made into something like json so that we can support discriminated unions for this case, because it doesn't really make sense to mix timestamp-based lines with azimuth-based ones. A JSON schema could probably validate it.

This converter could also help people to make their own dynamic wallpapers, provided that the photographs have a timestamp and GPS coordinates. This would be sufficient to calculate the azimuth and elevation for each photo.

xyproto commented 2 years ago

Hi, I created the heic package for extracting the timing metadata from .heic files and added a heic2stw utility and a heic-install script to wallutils in the main branch.

Could you please try the heic-install script and confirm that it is working?

xyproto commented 2 years ago

wallutils 5.10.0 now includes heic2stw and heic-install.

eddsalkield commented 2 years ago

Thanks for looking into this! I've taken a look at the implementation, and it seems like it's not taking into account the azimuth and elevation of the sun encoded within the metadata. This means that in certain seasons, and depending on your location, the sun may appear to set quite a long time after it's already dark, and the same for sunrise. Unfortunately, this is precisely what the heic file format seems designed to prevent.

Did you consider an extension to the stw format to take this into account, and if not, would you? I may also be missing something in your implementation here.

xyproto commented 2 years ago

Yes, adding azimuth and elevation would not be too much work, I think, now that other metadata can be extracted from .heic files.