image-info
Use the image-info endpoint to get metadata from an image.
The image-info
endpoint takes an HTTP POST form submission, where an image is sent as binary.
API
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
The ImageInfo
class encapsulates the image-info
endpoint. An ImageInfo
instance takes an ImageResource
instance. An ImageResource
is constructed from an image coming from a file, a byte array, or Stream
.
public ImageInfo(ImageResource resource);
public class ImageResource : Resource
{
public ImageResource(string filePath, string resourceName = null);
public ImageResource(byte[] value, string resourceName = null);
public ImageResource(Stream data, string resourceName = null);
}
The ImageInfo
class encapsulates the image-info
endpoint. An ImageInfo
instance takes an ImageResource
instance. An ImageResource
is constructed from an image coming from a file, a byte array, or InputStream
.
public ImageInfo(ImageResource resource);
public class ImageResource extends Resource
{
public ImageResource(String filePath, String resourceName);
public ImageResource(String filePath);
public ImageResource(byte[] value, String resourceName);
public ImageResource(byte[] value);
public ImageResource(InputStream data, String resourceName);
public ImageResource(InputStream data);
}
The ImageInfo
class encapsulates the image-info
endpoint. An ImageInfo
instance takes an ImageResource
instance. An ImageResource
is constructed from an image coming from a file or a byte array.
export class ImageInfo extends Endpoint {
constructor(resource);
}
export class ImageResource extends Resource {
/**
* Initializes a new instance of the `ImageResource` class.
* @param {string | Buffer[]} filePath The image file path. |
* The byte array of the image file.
* @param {string} resourceName The name of the resource.
*/
constructor(image, resourceName);
The ImageInfo
class encapsulates the image-info
endpoint. An ImageInfo
instance takes an ImageResource
instance. An ImageResource
is constructed from an image coming from a file or a byte array.
class ImageInfo extends Endpoint
{
public function __construct(ImageResource $resource)
}
class ImageResource extends Resource
{
/**
*
* Initializes a new instance of the ImageResource class.
*
* @param string|array|stream $filePath The image file path or
* the byte array of the image file or the stream of the image file.
* @param string $resourceName The name of the resource.
*/
public function __construct($file, string $resourceName = null)
The ImageInfo
class encapsulates the image-info
endpoint. An ImageInfo
instance takes an ImageResource
instance. An ImageResource
is constructed from an image coming from a file or a byte array.
// Represents an image information endpoint.
type ImageInfo struct {
Endpoint
resource resource.ImageResource
}
/*
Initializes a new instance of the `ImageInfo` class.
- @param {ImageResource} resource The image resource of type `ImageResource`.
*/
func NewImageInfo(image resource.ImageResource) *ImageInfo {
var ep ImageInfo
ep.resource = image
return &ep
}
type ImageResource struct {
Resource
}
func NewImageResourceWithResourcePath(resource string, resourceName string) ImageResource
func NewImageResourceWithByteValue(resource []byte, resourceName string) ImageResource
The ImageInfo
class encapsulates the image-info
endpoint. An ImageInfo
instance takes an ImageResource
instance. An ImageResource
is constructed from an image coming from a file, a byte array, or io.BytesIO
.
class ImageInfo(Endpoint):
def __init__(self, resource):
super().__init__()
self.resource = resource
self.EndpointName = "image-info"
Example
Refer to the following Users Guide page if you need more information illustrating how to call the endpoint directly as a REST call.
- Calling the
image-info
endpoint using REST (image-info REST API).
The complete example is available via one of the following GitHub projects depending upon the language you wish to use.
Language | GitHub Users Guide Project | Class | Location/Package/Namespace |
---|---|---|---|
C# | https://github.com/dynamicpdf-api/dotnet-client-examples | ImageInfoExample.cs | namespace Users_Guide_C_Sharp |
Go | https://github.com/dynamicpdf-api/go-client | image-info-example.go | go-client-examples |
Java | https://github.com/dynamicpdf-api/java-client-examples | ImageInfoExample.java | com.dynamicpdf.api.examples |
Node.js | https://github.com/dynamicpdf-api/nodejs-client-examples | ImageInfoExample.js | node-js-users-guide |
PHP | https://github.com/dynamicpdf-api/php-client-examples | ImageInfoExample.php | php-client-examples |
Python | https://github.com/dynamicpdf-api/python-client-examples | ImageInfoExample.py | python-client-examples |
For all six languages the syntax and logic is similar.
- Create a new
ImageResource
instance that holds the path to the image. - Create a new
ImageInfo
instance that holds the resource and then calls the endpoint. - The endpoint then returns the image metadata as a JSON document.
- C# (.NET)
- Java
- Node.js
- PHP
- Go
- Python
using DynamicPDF.Api;
using System;
namespace ImageInfoExample
{
class Program
{
static void Main(string[] args)
{
RunOne("DP.xxx-api-key-xxx", "C:/temp/dynamicpdf-api-usersguide-examples/");
RunTwo("DP.xxx-api-key-xxx", "C:/temp/dynamicpdf-api-usersguide-examples/");
}
public static void RunOne(String key, String basePath)
{
ImageResource imageResource = null;
imageResource = new ImageResource(basePath + "getting-started.png");
ImageInfo imageInfo = new ImageInfo(imageResource);
imageInfo.ApiKey = key;
ImageResponse response = imageInfo.Process();
Console.WriteLine(PrettyPrintUtil.JsonPrettify(response.JsonContent));
}
public static void RunTwo(String apiKey, String basePath)
{
String key = apiKey;
ImageResource imageResource = new ImageResource(basePath + "multipage.tiff");
ImageInfo imageInfo = new ImageInfo(imageResource);
imageInfo.ApiKey = apiKey;
ImageResponse response = imageInfo.Process();
Console.WriteLine(PrettyPrintUtil.JsonPrettify(response.JsonContent));
}
}
}
import {
ImageResource,
ImageInfo,
} from "@dynamicpdf/api"
export class ImageInfoExample {
static async Run() {
var basePath = "C:/temp/dynamicpdf-api-usersguide-examples/";
var apiKey = "DP.xxx-api-key-xxx";
await ImageInfoExample.RunOne(apiKey, basePath);
await ImageInfoExample.RunTwo(apiKey, basePath);
}
static async RunOne(apiKey, basePath) {
var imageResource = new ImageResource(basePath + "getting-started.png");
var imageInfo = new ImageInfo(imageResource);
imageInfo.apiKey = apiKey;
var response = await imageInfo.process();
if (response.isSuccessful) {
console.log(JSON.parse(response.content));
}
}
static async RunTwo(apiKey, basePath)
{
var imageResource = new ImageResource(basePath + "multipage.tiff");
var imageInfo = new ImageInfo(imageResource);
imageInfo.apiKey = apiKey;
var response = await imageInfo.process();
if (response.isSuccessful) {
console.log(JSON.parse(response.content));
}
}
}
await ImageInfoExample.Run();
package com.dynamicpdf.api.examples;
import com.dynamicpdf.api.ImageInfo;
import com.dynamicpdf.api.ImageResource;
import com.dynamicpdf.api.ImageResponse;
import com.dynamicpdf.api.util.PrettyPrintUtility;
public class ImageInfoExample {
package com.dynamicpdf.api.examples;
import com.dynamicpdf.api.ImageInfo;
import com.dynamicpdf.api.ImageResource;
import com.dynamicpdf.api.ImageResponse;
import com.dynamicpdf.api.util.PrettyPrintUtility;
public class ImageInfoExample {
public static void RunOne(String key, String basePath) {
ImageResource imageResource = null;
imageResource = new ImageResource(basePath + "/getting-started.png");
ImageInfo imageInfo = new ImageInfo(imageResource);
imageInfo.setApiKey(key);
ImageResponse response = imageInfo.process();
System.out.println(PrettyPrintUtility.prettyPrintJSON(response.getJsonContent()));
}
public static void RunTwo(String apiKey, String basePath)
{
String key = apiKey;
ImageResource imageResource = new ImageResource(basePath + "/multipage.tiff");
ImageInfo imageInfo = new ImageInfo(imageResource);
imageInfo.setApiKey(apiKey);
ImageResponse response = imageInfo.process();
System.out.println(PrettyPrintUtility.prettyPrintJSON(response.getJsonContent()));
}
public static void main(String[] args) {
ImageInfoExample.RunOne("DP.xxx-api-key-xxx",
"C:/temp/dynamicpdf-api-usersguide-examples/");
ImageInfoExample.RunTwo("DP.xxx-api-key-xxx",
"C:/temp/dynamicpdf-api-usersguide-examples/");
}
}
public static void main(String[] args) {
ImageInfoExample.RunOne("DP.xxx-api-key-xxx",
"C:/temp/dynamicpdf-api-usersguide-examples/");
ImageInfoExample.RunTwo("DP.xxx-api-key-xxx",
"C:/temp/dynamicpdf-api-usersguide-examples/");
}
}
<?php
require __DIR__ . '/vendor/autoload.php';
use DynamicPDF\Api\ImageResource;
use DynamicPDF\Api\ImageInfo;
class ImageInfoExample
{
private static string $BasePath = "C:/temp/dynamicpdf-api-usersguide-examples/";
private static string $ApiKey = "DP.xxx-api-key-xxx";
public static function Run(){
ImageInfoExample::RunOne();
ImageInfoExample::RunTwo();
}
public static function RunOne()
{
$imageResource = new ImageResource(ImageInfoExample::$BasePath . "getting-started.png");
$imageInfo = new ImageInfo($imageResource);
$imageInfo->ApiKey = ImageInfoExample::$ApiKey;
$response = $imageInfo->Process();
echo ($response->JsonContent);
}
public static function RunTwo()
{
$imageResource = new ImageResource(ImageInfoExample::$BasePath . "multipage.tiff");
$imageInfo = new ImageInfo($imageResource);
$imageInfo->ApiKey = ImageInfoExample::$ApiKey;
$response = $imageInfo->Process();
echo ($response->JsonContent);
}
}
ImageInfoExample::Run();
func RunOne(basePath string) {
resource := resource.NewImageResourceWithResourcePath(basePath + "/getting-started.png","")
imageInfo := endpoint.NewImageInfo(resource)
imageInfo.Endpoint.BaseUrl = "https://api.dpdf.io/"
imageInfo.Endpoint.ApiKey = "DP.xxx-api-key-xxx"
resp := imageInfo.Process();
res := <-resp
if res.IsSuccessful() == true {
fmt.Print(string(res.Content().Bytes()))
}
}
func RunTwo(basePath string) {
resource := resource.NewImageResourceWithResourcePath(basePath + "/multipage.tiff","")
imageInfo := endpoint.NewImageInfo(resource)
imageInfo.Endpoint.BaseUrl = "https://api.dpdf.io/"
imageInfo.Endpoint.ApiKey = "DP.xxx-api-key-xxx"
resp := imageInfo.Process();
res := <-resp
if res.IsSuccessful() == true {
fmt.Print(string(res.Content().Bytes()))
}
}
from dynamicpdf_api.image_resource import ImageResource
from dynamicpdf_api.image_info import ImageInfo
from Shared import *
def image_info(api_key, full_path):
resource = ImageResource(full_path + "getting-started.png")
image_info = ImageInfo(resource)
image_info.api_key = api_key
response = image_info.process()
print(response.json_content)
if __name__ == "__main__":
image_info(api_key, base_path + "/image-info/")