You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This function examines the specified media file for C2PA data and generates a JSON report of any data it finds. If there are validation errors, the report includes a `validation_status` field. For a summary of supported media types, see [Supported file formats](#supported-file-formats).
41
+
Use the `Reader` to read C2PA data from the specified file.
42
+
This examines the specified media file for C2PA data and generates a report of any data it finds. If there are validation errors, the report includes a `validation_status` field. For a summary of supported media types, see [Supported file formats](#supported-file-formats).
46
43
47
44
A media file may contain many manifests in a manifest store. The most recent manifest is identified by the value of the `active_manifest` field in the manifests map.
48
45
49
-
If the optional `data_dir` is provided, the function extracts any binary resources, such as thumbnails, icons, and C2PA data into that directory. These files are referenced by the identifier fields in the manifest store report.
46
+
The manifests may contain binary resources such as thumbnails which can be retrieved with `resource_to_stream` or `resource_to_file` using the associated `identifier` field values and a `uri`.
50
47
51
48
NOTE: For a comprehensive reference to the JSON manifest structure, see the [Manifest store reference](https://opensource.contentauthenticity.org/docs/manifest/manifest-ref).
49
+
```py
50
+
try:
51
+
reader = c2pa.Reader("path/to/media_file.jpg")
52
52
53
-
### Add a signed manifest to a media file
53
+
# Print the JSON for a manifest.
54
+
print("manifest store:", reader.json())
54
55
55
-
Use the `sign_file` function to add a signed manifest to a media file.
56
+
# Get the active manifest.
57
+
manifest = reader.get_active_manifest()
58
+
if manifest !=None:
56
59
57
-
```py
58
-
result = c2pa.sign_file("path/to/source.jpg",
59
-
"path/to/dest.jpg",
60
-
manifest_json,
61
-
sign_info,
62
-
data_dir)
63
-
```
60
+
# get the uri to the manifest's thumbnail and write it to a file
61
+
uri = manifest["thumbnail"]["identifier"]
62
+
reader.resource_to_file(uri, "thumbnail_v2.jpg")
64
63
65
-
The parameters (in order) are:
66
-
- The source (original) media file.
67
-
- The destination file that will contain a copy of the source file with the manifest data added.
68
-
-`manifest_json`, a JSON-formatted string containing the manifest data you want to add; see [Creating a manifest JSON definition file](#creating-a-manifest-json-definition-file) below.
69
-
-`sign_info`, a `SignerInfo` object instance; see [Generating SignerInfo](#generating-signerinfo) below.
70
-
-`data_dir` optionally specifies a directory path from which to load resource files referenced in the manifest JSON identifier fields; for example, thumbnails, icons, and manifest data for ingredients.
64
+
exceptExceptionas err:
65
+
print(err)
66
+
```
71
67
72
-
### Create a SignerInfo instance
68
+
### Add a signed manifest to a media file
73
69
74
-
A `SignerInfo` object contains information about a signature. To create an instance of `SignerInfo`, first set up the signer information from the public and private key `.pem` files as follows:
# At this point we could archive or unarchive our Builder to continue later.
132
+
# In this example we use a bytearray for the archive stream.
133
+
# all ingredients and resources will be saved in the archive
134
+
archive = io.BytesIO(bytearray())
135
+
builder.to_archive(archive)
136
+
archive.seek()
137
+
builder = builder.from_archive(archive)
86
138
87
-
For the list of supported signing algorithms, see [Creating and using an X.509 certificate](https://opensource.contentauthenticity.org/docs/c2patool/x_509).
139
+
# Sign and add our manifest to a source file, writing it to an output file.
140
+
# This returns the binary manifest data that could be uploaded to cloud storage.
0 commit comments