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 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 File 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 File 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 API's Portal. Refer to the following for instructions on getting an API key.

tip

If you are not familiar with the File 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.dpdf.io/v1.0/image-info" 
-H "Authorization: Bearer DP.xxx-api-key-xxx"
-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 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
GOimage-info-example.gogo-client-exampleshttps://github.com/dynamicpdf-api/go-client-examples/tree/main
PythonImageInfoExample.pypython-client-exampleshttps://github.com/dynamicpdf-api/python-client-examples
tip

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

Available on NuGet:

Install-Package DynamicPDF.API
  • Create a new Console App (.NET Core) project named GetImageInfo.
  • Add the DynamicPDF.API NuGet package.
  • Create a new static method named Run.
  • Add a new ImageResource instance and pass the path to the image in the constructor.
  • Create a new ImageInfo instance and pass the ImageResource instance to the constructor.
  • Add a call to the ImageInfo instance's Process method and return the response.
  • Check that the call was successful and print the image metadata as JSON to the console.
  • Run the application and the JSON image metadata appears in the console.
using DynamicPDF.Api;
using System;

namespace GetImageInfo
{
class Program
{
static void Main(string[] args)
{
Run("DP.xxx-api-key-xxx", "c:/temp/dynamicpdf-api-samples/get-image-info/");
}

public static void Run(String apiKey, String basePath)
{
ImageResource imageResource = new ImageResource(basePath + "dynamicpdflogo.png");
ImageInfo imageInfo = new ImageInfo(imageResource);
imageInfo.ApiKey = apiKey;
ImageResponse response = imageInfo.Process();

if(response.IsSuccessful)
{
Console.WriteLine(response.JsonContent);
} else
{
Console.WriteLine(response.ErrorJson);
}
}
}
}

In all six 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.

   Follow us on social media for latest news!