# `Image.Privacy`
[🔗](https://github.com/elixir-image/image/blob/v0.74.0/lib/image/privacy.ex#L1)

Finds tracking and identifying data in an image's metadata.

`scan/1` reads an image's IPTC, EXIF, XMP and PNG text, a JPEG
file's comment segments, and data hidden after the end of a JPEG or
PNG file, and returns
an `Image.Privacy.Finding` for each piece of data that could
identify a person, a device, a place or the image itself, or that
a platform added to follow the image: Facebook's `FBMD` identifier,
camera serial numbers, GPS coordinates, the document identifiers
editing software writes, AI labels and generator prompts. It also
reports an EXIF thumbnail, a second copy of the picture that can
show it before it was cropped or edited.

`remove/2` removes the data that chosen findings describe and keeps
the rest. `Image.remove_metadata/2`, or `strip_metadata: true` in
`Image.write/3`, removes whole blocks. The
[Privacy and tracking metadata](privacy.md) guide covers both.

### What the scan cannot find

* **Invisible watermarks** embedded in the pixels, such as Google
  SynthID, Meta's Video Seal and Digimarc, can only be read with the
  vendor's own decoder. A scan with no findings is not evidence that
  an image carries no watermark.

* **Maker notes**, the camera maker's own block in EXIF, can hold a
  body serial number or the owner's name. They are not read yet. They
  are removed with the rest of the EXIF by `strip_metadata: true` and
  `Image.remove_metadata(image, :exif)`.

* **Data outside the decoded image** is not visible to libvips. For a
  JPEG or PNG given as a path or binary, the scan reads the file's
  segments or chunks for comment segments and data after the end of
  the image; given an image, it cannot. Other formats are not read
  this way. Any image `Image` writes leaves this data out.

* **C2PA Content Credentials** are not reported. They record an
  image's authenticity rather than track it, and libvips has no API
  to read them. libvips does not carry a JPEG's credentials through
  a save either, so a JPEG `Image` writes has none.

# `remove`
*since 0.74.0* 

```elixir
@spec remove(Vix.Vips.Image.t(), [Image.Privacy.Finding.t()]) ::
  {:ok, Vix.Vips.Image.t()} | {:error, Image.Error.t()}
```

Removes the data that findings from `scan/1` describe, keeping the
rest of the image's metadata.

### Arguments

* `image` is any `t:Vix.Vips.Image.t/0`.

* `findings` is a list of `t:Image.Privacy.Finding.t/0`, usually
  a selection of what `scan/1` returned for the same image.

### Returns

* `{:ok, image}` with the data removed. The removal takes effect
  when the image is saved, or

* `{:error, %Image.Error{reason: :invalid_finding}}` if a list
  element is not a finding, or

* `{:error, %Image.Error{reason: :invalid_iptc}}` or
  `{:error, %Image.Error{reason: :invalid_xmp}}` if the image's IPTC
  or XMP cannot be read to remove a finding from it, or

* `{:error, %Image.Error{reason: :unsupported_finding}}` for a
  finding this function does not know how to remove.

### Notes

* A `:gps` finding removes the whole EXIF GPS block, including its
  timestamps and altitude. A `:gps_destination` finding removes only
  the destination.

* An `:unreadable` finding removes the whole block it refers to.

* IPTC findings are removed by rewriting the IPTC block without them.
  Its other datasets and Photoshop resources are kept, and the block
  is removed when no content is left.

* XMP findings are removed from the XMP packet in place, keeping
  every other property byte for byte. `:region_names` removes the
  face regions whole, with their coordinates, and `:people_in_image`
  both IPTC lists of people. GPS inside an IPTC location structure
  describes that location and is kept when the image's GPS is
  removed.

* Findings from a JPEG's or PNG's segments, such as comments and
  data after the end of the image, need nothing removed: libvips
  never reads them, so no image `Image` writes contains them. The
  EXIF host computer, camera serial number, photographer and image
  editor are likewise dropped by every save.

### Examples

    iex> image = Image.open!("./test/support/images/gain_map.jpg")
    iex> {:ok, findings} = Image.Privacy.scan(image)
    iex> remove = Enum.filter(findings, &(&1.kind in [:location, :device_id]))
    iex> {:ok, image} = Image.Privacy.remove(image, remove)
    iex> {:ok, jpeg} = Image.write(image, :memory, suffix: ".jpg")
    iex> {:ok, findings} = Image.Privacy.scan(jpeg)
    iex> Enum.map(findings, & &1.field)
    [:artist, :thumbnail]

# `scan`
*since 0.74.0* 

```elixir
@spec scan(Vix.Vips.Image.t() | Path.t() | binary()) ::
  {:ok, [Image.Privacy.Finding.t()]} | {:error, Image.Error.t()}
```

Scans an image for tracking and identifying data.

### Arguments

* `image` is any `t:Vix.Vips.Image.t/0`, the path to an image file,
  or an image file's bytes. A binary that starts with an image
  signature is treated as the file's bytes, as in `Image.open/2`.
  Given a path or bytes, a JPEG's segments and a PNG's chunks are
  read as well as its metadata.

### Returns

* `{:ok, findings}` where `findings` is a list of
  `t:Image.Privacy.Finding.t/0`, in the order IPTC, EXIF, XMP, PNG
  text, JPEG segments and PNG chunks. An image with nothing to report returns an
  empty list, or

* `{:error, %Image.Error{}}` if the file cannot be read or opened as
  an image, with reason `:invalid_image` if `image` is not an image,
  a path or a binary.

### Examples

    iex> image = Image.open!("./test/support/images/Kip_small.jpg")
    iex> {:ok, findings} = Image.Privacy.scan(image)
    iex> Enum.find(findings, &(&1.source == :iptc and &1.kind == :person))
    %Image.Privacy.Finding{source: :iptc, field: :by_line, value: ["Kip Cole"], kind: :person}

    iex> {:ok, findings} = Image.Privacy.scan("./test/support/images/kodak-dc210.jpg")
    iex> Enum.find(findings, &(&1.field == :comment)).value
    "Lovely smoke effect here, of which I'm secretly very proud."

    iex> Image.Privacy.scan(Image.new!(16, 16))
    {:ok, []}

---

*Consult [api-reference.md](api-reference.md) for complete listing*
