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
Fields | Type | Description |
---|---|---|
img | URL | Input media URL. If you want to upload your image directly from your app, then submit a multipart/form-data POST request. |
key | String | Your 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:
Fields | Type | Description |
---|---|---|
status | Integer | Status code 200 indicates success, any other code indicates failure. |
width | Integer | Width of the input image. |
height | Integer | Height of the input image. |
type | String | Image type format such JPEG, PNG, GIF, etc. |
size | Integer | Image size in Bytes. |
mime | String | Image MIME type. |
channels | Integer | Total Image channels. e.g. 3 for RGB colorspace, 1 for grayscale image, etc. |
bits | Integer | Total bits for each color. |
html_attr | String | String with Height & Width that takes the form height="128" width="64" suitable for HTML embedding. |
css_prop | String | String with Height & Width that takes the form height:128px;width:64px; suitable for CSS embedding. |
error | String | Error 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
nsfw, sfw, ocr, facedetect, facelandmarks, grayscale, rotate, crop, tagimg, mogrify, blur, facecompare, facelookup, screencapture