Module: C2paXmpProbe

Defined in:
lib/c2pa_xmp_probe.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

VERSION =
"0.1.0"
C2PA_MARKERS =
%w[c2pa C2PA jumb c2ma c2cl c2cs c2as].freeze
XMP_MARKERS =
[
  "http://ns.adobe.com/xap/1.0/",
  "<x:xmpmeta",
  "xmlns:xmp",
  "photoshop:DocumentAncestors"
].freeze
AI_HINT_MARKERS =
[
  "Firefly",
  "Midjourney",
  "Stable Diffusion",
  "DALL-E",
  "DALLĀ·E",
  "Content Credentials",
  "madewithai",
  "Made with AI"
].freeze

Class Method Summary collapse

Class Method Details

.probe_bytes(data, path: "<memory>") ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/c2pa_xmp_probe.rb', line 37

def probe_bytes(data, path: "<memory>")
  matched = []
  has_c2pa = false
  has_xmp = false
  has_ai_hint = false

  C2PA_MARKERS.each do |marker|
    next unless data.include?(marker)

    has_c2pa = true
    matched << marker
  end

  XMP_MARKERS.each do |marker|
    next unless data.include?(marker)

    has_xmp = true
    matched << marker[0, 48]
  end

  AI_HINT_MARKERS.each do |marker|
    next unless data.include?(marker)

    has_ai_hint = true
    matched << marker
  end

  Result.new(
    path: path,
    size: data.bytesize,
    has_c2pa: has_c2pa,
    has_xmp: has_xmp,
    has_ai_hint: has_ai_hint,
    matched: matched.uniq
  )
end

.probe_file(file_path) ⇒ Object



74
75
76
77
# File 'lib/c2pa_xmp_probe.rb', line 74

def probe_file(file_path)
  data = File.binread(file_path)
  probe_bytes(data, path: file_path)
end