Calculate crop API
Calculate the crop box that fits an image to a social media size.
- Endpoint:
POST https://postboost.co/app/api/tools/social-media-image-sizes/crop(operationIdcalculateCrop) - Web tool: postboost.co/tools/social-media-image-sizes
- Token: optional (limits)
- MCP: tool
calculate-croponhttps://postboost.co/mcp/tools
Request
| Field | Type | Default | Description |
|---|---|---|---|
width | integer | Source image width in pixels. | |
height | integer | Source image height in pixels. | |
network | string | Network key from getImageSizes (network_key), e.g. instagram. With format, picks the target size. | |
format | string | Format key from getImageSizes (format_key), e.g. feed-square. | |
target_width | integer | Target width in pixels, instead of network + format. | |
target_height | integer | Target height in pixels, instead of network + format. | |
fit | string: cover, contain | "cover" | cover crops to fill the target; contain keeps the whole image and centres it. |
Call it
- curl
- Python
- Node.js
- PHP
- Go
- Ruby
- Java
- C#
- Rust
- CLI
curl -X POST https://postboost.co/app/api/tools/social-media-image-sizes/crop \
-H 'Content-Type: application/json' \
-d '{"width":4000,"height":3000,"network":"instagram","format":"feed-square"}'
from postboost import ApiClient, Configuration
from postboost.api.free_tools_api import FreeToolsApi
from postboost.models import FreeToolCalculateCropRequest
with ApiClient(Configuration()) as client:
api = FreeToolsApi(client)
result = api.calculate_crop(FreeToolCalculateCropRequest.from_dict({"width": 4000, "height": 3000, "network": "instagram", "format": "feed-square"}))
print(result.to_dict())
import { FreeToolsApi } from 'postboost';
const api = new FreeToolsApi();
const { body } = await api.calculateCrop({ width: 4000, height: 3000, network: "instagram", format: "feed-square" });
console.log(body);
use PostBoostClient\Api\FreeToolsApi;
use PostBoostClient\Model\FreeToolCalculateCropRequest;
$api = new FreeToolsApi(new GuzzleHttp\Client());
$result = $api->calculateCrop(new FreeToolCalculateCropRequest(['width' => 4000, 'height' => 3000, 'network' => "instagram", 'format' => "feed-square"]));
echo $result;
import (
"context"
"encoding/json"
"fmt"
postboost "github.com/postboost-co/postboost-go"
)
var request postboost.FreeToolCalculateCropRequest
if err := json.Unmarshal([]byte(`{"width":4000,"height":3000,"network":"instagram","format":"feed-square"}`), &request); err != nil {
panic(err)
}
client := postboost.NewAPIClient(postboost.NewConfiguration())
result, _, err := client.FreeToolsAPI.CalculateCrop(context.Background()).FreeToolCalculateCropRequest(request).Execute()
fmt.Println(result, err)
require 'postboost'
api = PostBoost::FreeToolsApi.new
result = api.calculate_crop(PostBoost::FreeToolCalculateCropRequest.new({ width: 4000, height: 3000, network: "instagram", format: "feed-square" }))
puts result.to_hash
import com.postboost.ApiClient;
import com.postboost.api.FreeToolsApi;
import com.postboost.model.FreeToolCalculateCropRequest;
import com.postboost.model.FreeToolCalculateCropResponse;
FreeToolsApi api = new FreeToolsApi(new ApiClient());
FreeToolCalculateCropRequest request = FreeToolCalculateCropRequest.fromJson("{\"width\":4000,\"height\":3000,\"network\":\"instagram\",\"format\":\"feed-square\"}");
FreeToolCalculateCropResponse result = api.calculateCrop(request);
System.out.println(result.toJson());
using Newtonsoft.Json;
using PostBoost.Client.Api;
using PostBoost.Client.Client;
using PostBoost.Client.Model;
var api = new FreeToolsApi(new Configuration());
var request = JsonConvert.DeserializeObject<FreeToolCalculateCropRequest>(@"{""width"":4000,""height"":3000,""network"":""instagram"",""format"":""feed-square""}");
var result = await api.CalculateCropAsync(request);
Console.WriteLine(result.ToJson());
use postboost::apis::configuration::Configuration;
use postboost::apis::free_tools_api;
use postboost::models::FreeToolCalculateCropRequest;
let config = Configuration::new();
let request: FreeToolCalculateCropRequest = serde_json::from_str(r##"{"width":4000,"height":3000,"network":"instagram","format":"feed-square"}"##)?;
let result = free_tools_api::calculate_crop(&config, request).await?;
println!("{:?}", result);
echo '{"width":4000,"height":3000,"network":"instagram","format":"feed-square"}' | ./postboost-cli --content-type application/json calculateCrop -
With a token, send Authorization: Bearer YOUR_API_TOKEN as a default header (how, per SDK).
Response
{
"crop": {
"x": 500,
"y": 0,
"width": 3000,
"height": 3000
},
"output": {
"width": 1080,
"height": 1080
},
"image": {
"x": 0,
"y": 0,
"width": 1080,
"height": 1080
},
"scale": 0.36,
"upscaled": false
}
With MCP
Connect https://postboost.co/mcp/tools (setup) and ask, for example: Calculate the crop box that fits an image to a social media size with the PostBoost calculate-crop tool.
Errors
| Status | When |
|---|---|
401 | The Authorization header holds an invalid token. Leave it out to call as a guest. |
413 | The JSON body is larger than 128 KB. |
422 | A field is invalid; the body lists the errors per field. |
429 | A limit is reached; see limits. |