Version 1.9.72 (Release Notes)


converthttps://api.pixlab.io/convert

Description

Convert a static image to another format such as JPEG to PNG, BMP to TIFF, etc. The output image will keep its original dimension. Call resize, crop, thumbnail, avatar, etc. if you want to adjust the width & height of the output image. For GIF conversion, please rely on makegif instead.

HTTP Methods

GET, POST

Request Parameters

Required

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

Optional
FieldsTypeDescription
blobBooleanBy default, this command return a JSON object holding the link to the image output. But, if this parameter is set to true then the image binary contents is returned instead.
backgroundStringBackground color if any. Use hex color code such as #cef45f if you want to. If you want a transparent background, pass the magic word tr or transparent.
compressionIntegerJPEG Compression quality. A value between 0..100. Valid only for JPEG conversion.

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 image directly (refer to the sample set for a working example). If you are using JSON, then your image must be already uploaded somewhere. Call store if you want to upload an image for example before invoking this endpoint.

Response

application/json if the optional blob parameter is not set.

This command return a JSON object after each call only if the optional blob parameter is not set. Otherwise the image binary contents is returned instead. The following are the JSON fields returned in response body:

FieldsTypeDescription
statusIntegerStatus code 200 indicates success, any other code indicates failure.
linkURLLink to the media output which is usually stored on the pixlab.xyz storage server unless you set your own S3 keys (refer to your dashboard on how to do that).
idStringUnique media ID.
errorStringError message if status != 200.

Python Example

import requests
import json

# Convert JPEG image to PNG with transparent background.
# https://pixlab.io/cmd?id=convert for more info.

req = requests.get('https://api.pixlab.io/convert',params={
	'img':'https://www.allaboutbirds.org/guide/PHOTO/LARGE/blue_jay_8.jpg',
	'export': 'png',
	'background':'tr',
	'key':'Pix_Key'
})
reply = req.json()
if reply['status'] != 200:
	print (reply['error'])
else:
    print ("Pic Link: "+ reply['link'])

See Also