Version 1.9.72 (Release Notes)


headerhttps://api.pixlab.io/header

Description

Extract image meta information such as height, width, size, MIME type and so forth (See response object below for the list of meta-data returned).

HTTP Methods

GET, POST

Request Parameters

Required

FieldsTypeDescription
imgURLInput media URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request.
keyStringYour PixLab API Key. You can also embed your key in the WWW-Authenticate: HTTP header and omit this parameter if you want to.

POST Request Body (If you plan to use POST instead of a simple GET request)

Allowed Content-Type:

multipart/form-data
application/json

Use multipart/form-data if you want to upload your media file directly (refer to the sample set for a working example). If you are using JSON, then the media file must be already uploaded somewhere. Call store if you want to upload an image for example before invoking this endpoint.

Response

application/json

This command always return a JSON object whether successful or not after each call. The following are the JSON fields returned in response body:

FieldsTypeDescription
statusIntegerStatus code 200 indicates success, any other code indicates failure.
widthIntegerWidth of the input image.
heightIntegerHeight of the input image.
typeStringImage type format such JPEG, PNG, GIF, etc.
sizeIntegerImage size in Bytes.
mimeStringImage MIME type.
channelsIntegerTotal Image channels. e.g. 3 for RGB colorspace, 1 for grayscale image, etc.
bitsIntegerTotal bits for each color.
html_attrStringString with Height & Width that takes the form height="128" width="64" suitable for HTML embedding.
css_propStringString with Height & Width that takes the form height:128px;width:64px; suitable for CSS embedding.
errorStringError message if status != 200.

Python Example

import requests
import json

# Check if a given image is of the right size: 800x600 and if not try to resize it.
# The command of interest here are header: https://pixlab.io/cmd?id=header & smartresize: https://pixlab.io/cmd?id=smartresize
img = 'https://s-media-cache-ak0.pinimg.com/736x/60/aa/e4/60aae45858ab6ce9dc5b33cc2e69baf7.jpg'

key = 'My_PixLab_Key'
# Obtain image metadata at first via header
req = requests.get('https://api.pixlab.io/header',params={'img':img,'key':key})
reply = req.json()
if reply['status'] != 200:
	print (reply['error'])
	exit()
w = reply['width']
h =  reply['height']
if w > 800 or h > 600:
	print("Resizing image from "+str(w)+"x"+str(h)+" to near 800x600...")
	# Invoke smart resize...
	req = requests.get('https://api.pixlab.io/smartresize',params={'img':img,'key':key,'width':800,'height':600})
	reply = req.json()
	if reply['status'] != 200:
		print (reply['error'])
	else:
		print("Resized image: "+reply['link'])
else:
	print("Uploaded image is of the correct size!")

See Also