VK Cloud logo
Updated atMarch 20, 2024   06:18 AM

Image processing methods

The improve method is used to enhance photos.

Request

Authorization data is passed in the query string:

Parameter
Type
Meaning
oauth_token
string
OAuth2 access token (required non-empty)
oauth_provider
string
OAuth2 provider (required non-empty)

Supported OAuth2 providers:

Provider
oauth_provider value
Getting a token
VK Cloud
mcs
See in the article

Request parameters are passed in JSON format in the request body with name="meta":

Parameter
Type
Meaning
mode
[]string
Types of objects to be searched for in the passed images (required non-empty)
images
[]image_meta
Transferred image metadata (required non-empty)
rfactor
int
Resolution increase factor, can be either 2 or 4 (required non-empty for resolution mode)
ftype
string
Image type, "art" or "photo" (required non-empty for resolution mode)

Possible values ​​for mode:

Parameter
Meaning
improve
Photo recovery
resolution
Resolution increase

image_meta parameters:

Parameter
Type
Meaning
name
string
Filenames to match files in request and response (required non-empty)

Images are passed in the body of the request, the values ​​of the name field must match those passed in images.

Request example

1curl -X 'POST'   'https://smarty.mail.ru/api/v1/photo/improve?oauth_token=<ваш токен>&oauth_provider=mcs'   -H 'accept: application/json'   -H 'Content-Type: multipart/form-data'   -F 'file=@photo_imrove_improve_ok.jpg;type=image/jpeg'   -F 'meta={
2  "mode": [
3    "improve"
4  ],
5  "images": [
6    {
7      "name": "file"
8    }
9  ]
10}'

Response

Parameter
Type
Meaning
status
int
200 on success, otherwise the error description will be in body
body
string
Response body

response parameters:

Parameter
Type
Meaning
improve
[]improve_object
Array of responses for improve mode
resolution
[]resolution_object
Array of responses for resolution mode

improve_object parameters:

Parameter
Type
Meaning
status
enum
Execution result
error
string
Text description of the error (optional)
name
string
File name to match files in request and response
improved
string
Jpeg picture of a photograph with defects corrected (base64). The field may be absent or empty if, according to the algorithm, there is no point in restoring the photo (it is already good)
colorized_improved
string
Jpeg picture of a photograph with defects corrected and color restored (base64). The field may be absent or empty if, according to the algorithm, the photo does not make sense to restore and paint over
colored
string
Jpeg picture of a photo with restored color (base64)
bw
bool
True - the algorithm considers that it was given a black-and-white photo as input, false - algoritm believes that he was given a color photo at the entrance

resolution_object parameters:

Parameter
Type
Meaning
status
enum
Execution result
error
string
Text description of the error (optional)
name
string
File name to match files in request and response
resolved
string
Jpeg picture of a photo with increased resolution (base64)

status parameters:

Parameter
Meaning
0
Successfully
1
Permanent error
2
Temporary error

Response example

1{
2  "status": 200,
3  "body": {
4    "improve": [
5      {
6        "status": 0,
7        "name": "file",
8        "improved": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgrdN6OW4fD17xGW9rNFH51rZO6fc/wBJl/eVinwtrWeShPc10C/8gt6wK8CGx3H/2Q==",
9        "colorized_improved": "/9j/4AAQSkZJRgABAQAAAQABAAD/8AXKOs6NWdR22KdVvT+ugy3tZoo/OtbJ3T7n+ky/vKxT4W1rPJQnua6Bf+QW9YFelTWhnY/9k=",
10        "colorized": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/XQZb2s0UfnWtk7p9z/SZf3lYp8La1nkoT3NdAv/ILesCvUpK6IP/Z",
11        "bw": true
12      }
13    ]
14  },
15  "htmlencoded": false,
16  "last_modified": 0
17}

Additional examples

Increasing the image resolution

Request example:

1curl -X 'POST' \
2  'https://smarty.mail.ru/api/v1/photo/improve?oauth_token=<ваш токен>&oauth_provider=mcs' \
3  -H 'accept: application/json' \
4  -H 'Content-Type: multipart/form-data' \
5  -F 'file=@photo_imrove_resolution_ok.jpeg;type=image/jpeg' \
6  -F 'meta={
7  "mode": [
8    "resolution"
9  ],
10  "rfactor": 2,
11  "rtype": "photo",
12  "images": [
13    {
14      "name": "file"
15    }
16  ]
17}'

Response example:

1{
2  "status": 200,
3  "body": {
4    "resolution": [
5      {
6        "status": 0,
7        "name": "file",
8        "resolved": "/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAIBAQEBAQIBAQECAgICAgQDAgICAgUEBAMEBgUGBgYFBgYGBwkIBgcJBwYGCAsICQoKCgoKBggLDAsKDAkKCgr/6a+9FFZSSUj0MPqf/9k="
9      }
10    ]
11  },
12  "htmlencoded": false,
13  "last_modified": 0
14}

Incorrect rfactor

Request example:

1curl -X 'POST'   'https://smarty.mail.ru/api/v1/photo/improve?oauth_token=<ваш токен>&oauth_provider=mcs'   -H 'accept: application/json'   -H 'Content-Type: multipart/form-data'   -F 'file=@photo_imrove_resolution_ok.jpeg;type=image/jpeg'   -F 'meta={
2  "mode": [
3    "resolution"
4  ],
5  "rfactor": 1010,
6  "rtype": "photo",
7  "images": [
8    {
9      "name": "file"
10    }
11  ]
12}'

Response example:

1{
2  "status": 400,
3  "body": "rfactor must be 2 or 4",
4  "htmlencoded": false,
5  "last_modified": 0
6}

Invalid image

Request example:

1curl -X 'POST'   'https://smarty.mail.ru/api/v1/photo/improve?oauth_token=<ваш токен>&oauth_provider=mcs'   -H 'accept: application/json'   -H 'Content-Type: multipart/form-data'   -F 'file=@empty.jpg;type=image/jpeg'   -F 'meta={
2  "mode": [
3    "resolution"
4  ],
5  "rfactor": 2,
6  "rtype": "photo",
7  "images": [
8    {
9      "name": "file"
10    }
11  ]
12}'

Response example:

1{
2  "status": 400,
3  "body": "empty image",
4  "htmlencoded": false,
5  "last_modified": 0
6}

Invalid meta parameter

Request example:

1curl -X 'POST'   'https://smarty.mail.ru/api/v1/photo/improve?oauth_token=<ваш токен>&oauth_provider=mcs'   -H 'accept: application/json'   -H 'Content-Type: multipart/form-data'   -F 'file=@photo_imrove_resolution_ok.jpeg;type=image/jpeg'   -F 'meta={
2  "mode": [
3    "resolution"
4  ],
5  "rfactor": 2,
6  "rtype": "photo",
7  "images": [
8    {
9      "name": "file1"
10    }
11  ]
12}'

Response example:

1{
2  "status": 400,
3  "body": "could not get image by name file1: http: no such file",
4  "htmlencoded": false,
5  "last_modified": 0
6}