Skip to main content

Extract Image Metadata


Use the image-info endpoint to get metadata describing an image.


The image-info endpoint is for obtaining metadata describing an image. In this tutorial we illustrate using this endpoint to obtain an image's metadata. We first call the image-info REST endpoint directly using cURL. We then use the DynamicPDF Cloud API client libraries to programmatically call the endpoint.

Required Resources#

To complete this tutorial, you must add the Get Image Information (image-info Endpoint) sample to your samples folder in your cloud storage space using the the Resource Manager. After adding the sample resources, you should see a samples/get-image-info-image-info-endpoint folder containing the resources for this tutorial.

SampleSample FolderResources
Get Image Information (image-info Endpoint)samples/get-image-info-image-info-endpointdynamicpdfLogo.png
  • From the Resource Manager, download dynamicpdfLogo.png to your local system; here we assume /temp/dynamicpdf-api-samples/get-image-info.
ResourceCloud/Local
dynamicpdfLogo.pnglocal
tip

See Sample Resources for instructions on adding sample resources.

Obtaining API Key#

This tutorial assumes a valid API key obtained from the DynamicPDF Cloud API's Environment Manager. Refer to the following for instructions on getting an API key.

tip

If you are not familiar with the Resource Manager or Apps and API Keys, refer to the following tutorial and relevant Users Guide pages.

Make Request Using API#

The image-info endpoint is a form post that takes the API key in the header and the image as binary data in the request's body. The following uses cURL to make an HTTP POST request, passing the image as binary data. Note that in the Header we pass the Content-Type as image/png.

curl -X POST "https://api.dynamicpdf.com/v1.0/image-info" -H "Authorization: Bearer DP.xxxx--api-key--xxxxx" -H  "Content-Type: image/png" --data-binary "@c:/temp/dynamicpdf-api-samples/get-image-info/dynamicpdflogo.png"

Examine API Response#

The REST call returns the following JSON describing the image.

[  {    "pageNumber": 1,    "width": 262,    "height": 250,    "horizondalDpi": 300,    "verticalDpi": 300,    "numberOfComponents": 3,    "bitsPerComponent": 8,    "colorSpace": "indexed"  }]
info

The JSON response returns an array so that the endpoint can support multi-page tiffs. Refer to the Users Guide for an example using a multi-page tiff image.

Make Request Using Client Library#

Now let's use the a client library to call the REST endpoint. To simplify your development, you can use any of the DynamicPDF Cloud API client libraries to complete this tutorial section. Each client library tab contains tutorial steps particular to the selected language.

Complete Source#

You can access the complete source for this project at one of the following GitHub projects.

LanguageFile NameLocation (package/namespace/etc.)GitHub Project
JavaGetImageInfo.javacom.dynamicpdf.api.exampleshttps://github.com/dynamicpdf-api/java-client-examples
C#Program.csGetImageInfohttps://github.com/dynamicpdf-api/dotnet-client-examples
NodejsGetImageInfo.jsnodejs-client-exampleshttps://github.com/dynamicpdf-api/nodejs-client-examples
PHPGetImageInfo.phpphp-client-exampleshttps://github.com/dynamicpdf-api/nodejs-client-examples
tip

Click on the language tab of choice to view the tutorial steps for the particular language.


In all four languages, the steps were similar. First, we created a new ImageResource instance by loading the path to the image via the constructor. Next, we created a new instance of the ImageInfo class, which abstracts the image-info endpoint. Then the ImageInfo instance prints the extracted image information as JSON after processing. Finally, we called the Process method and print the resultant JSON to the console.