Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Read Alt Text From An Image/Photo In Rust

This is a work in progress.

The goal here is to come up with a way to read the IPTC metadata information for an image to pull the alt text automatically for Neopoligen.

Note that I had to install gexiv2 to get this to work. I did this on my mac with: `brew install gexiv2``

Code

```cargo
[dependencies]
rexiv2 = "0.10"
```

fn main() {
  let file = "images/iptc-headline-metadata-test.png";
  let tag = "Iptc.Application2.Headline";
  match rexiv2::Metadata::new_from_path(&file) {
    Ok(meta) => 
    {
      println!("{:?}", meta.get_tag_multiple_strings(tag));
      dbg!(meta.has_iptc());
      dbg!(meta.supports_iptc());
      dbg!(meta.has_xmp());
    },
    Err(e) => 
      println!("{}", e)
  }
}

Results

Ok([])

[/Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:13:7] meta.has_iptc() = false
[/Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:14:7] meta.supports_iptc() = true
[/Users/alan/.cargo/target/55/19854259915251/_active_nvim_run:15:7] meta.has_xmp() = true

NOTE: This is the original response I got when I tired to run the process.

error: failed to run custom build command for `gexiv2-sys v1.4.0`

Caused by:
  process didn't exit successfully: `/Users/alan/.cargo/target/55/19854259915251/debug/build/gexiv2-sys-ae7041b700b82523/build-script-build` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=GEXIV2_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=GEXIV2_STATIC
  cargo:rerun-if-env-changed=GEXIV2_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_STATIC
  cargo:rerun-if-env-changed=PKG_CONFIG_ALL_DYNAMIC
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_PATH
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_LIBDIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64-apple-darwin
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_aarch64_apple_darwin
  cargo:rerun-if-env-changed=HOST_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR

  The gexiv2 library was not found by pkg-config on your system.

  Consult the README.md file for suggestions on how to acquire it.

  --- stderr
  thread 'main' panicked at /Users/alan/.cargo/registry/src/index.crates.io-6f17d22bba15001f/gexiv2-sys-1.4.0/build.rs:28:13:

  pkg-config exited with status code 1
  > PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 pkg-config --libs --cflags gexiv2

  The system library `gexiv2` required by crate `gexiv2-sys` was not found.
  The file `gexiv2.pc` needs to be installed and the PKG_CONFIG_PATH environment variable must contain its parent directory.
  The PKG_CONFIG_PATH environment variable is not set.

  HINT: if you have installed the library, try setting PKG_CONFIG_PATH to the directory containing `gexiv2.pc`.

  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

References