How to Get Image Information in C/C++

Cloudmersive
1 min readMay 24, 2021

Retrieving details from images can provide valuable insight into image standards, processing, and more. However, it’s not always the easiest task to accomplish. To simplify the extraction of information from an image, you can use the following API in C/C++ to perform the task in seconds.

First, we will install libcurl into our project:

libcurl/7.75.0

With the installation out of the way, we are ready to input the image file and call the function:

CURL *curl;
CURLcode res;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(curl, CURLOPT_URL, "https://api.cloudmersive.com/convert/image/get-info");
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_DEFAULT_PROTOCOL, "https");
struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "Content-Type: multipart/form-data");
headers = curl_slist_append(headers, "Apikey: YOUR-API-KEY-HERE");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_mime *mime;
curl_mimepart *part;
mime = curl_mime_init(curl);
part = curl_mime_addpart(mime);
curl_mime_name(part, "inputFile");
curl_mime_filedata(part, "/path/to/file");
curl_easy_setopt(curl, CURLOPT_MIMEPOST, mime);
res = curl_easy_perform(curl);
curl_mime_free(mime);
}
curl_easy_cleanup(curl);

After the request is sent to the server, a wide range of information will be returned; the below snapshot provides a complete summary of the extracted details:

{
"Successful": true,
"ColorSpace": "string",
"ColorType": "string",
"Width": 0,
"Height": 0,
"CompressionLevel": 0,
"ImageHashSignature": "string",
"HasTransparency": true,

--

--

Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.