curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"mediaUrl": "https://img.ayrshare.com/012/gb.jpg", "platform": "instagram"' \
-X POST https://api.ayrshare.com/api/media/resize
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/media/resize", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`
},
body: JSON.stringify({
mediaUrl: "https://img.ayrshare.com/012/gb.jpg", // required
platform: "instagram"
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'mediaUrl': 'https://img.ayrshare.com/012/gb.jpg',
'platforms': 'instagram'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://api.ayrshare.com/api/media/resize',
json=payload,
headers=headers)
print(r.json())
<?php
$curl = curl_init();
$data = array (
"mediaUrl" => "https://img.ayrshare.com/012/gb.jpg",
"platforms" => "instagram"
);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.ayrshare.com/api/media/resize',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer API_KEY',
'Accept-Encoding: gzip'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class AyrshareApiClient
{
private readonly HttpClient _httpClient;
private readonly string _apiKey;
private const string BaseUrl = "https://api.ayrshare.com/api";
public AyrshareApiClient(string apiKey)
{
_apiKey = apiKey ?? throw new ArgumentNullException(nameof(apiKey));
_httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_apiKey}");
}
public async Task<string> ResizeMediaAsync(string mediaUrl, string platform)
{
try
{
var requestData = new
{
mediaUrl = mediaUrl,
platform = platform
};
var content = new StringContent(
JsonSerializer.Serialize(requestData),
Encoding.UTF8,
"application/json"
);
var response = await _httpClient.PostAsync($"{BaseUrl}/media/resize", content);
response.EnsureSuccessStatusCode();
var jsonResponse = await response.Content.ReadAsStringAsync();
return jsonResponse;
}
catch (HttpRequestException ex)
{
throw new Exception($"Failed to resize media: {ex.Message}", ex);
}
}
public void Dispose()
{
_httpClient.Dispose();
}
}
{
"status": "success",
"url": "https://media.ayrshare.com/9abf1426d6ce9122ef11c72bd62e59807c5cc083/8UbyBjHTxgHkAC1I37e6O.jpg",
"platform": "instagram",
"mode": "blur",
"effects": {
"color": "#A020F0"
}
}
{
"action": "resize",
"status": "error",
"code": 312,
"message": "Invalid extension type. Extension: null. Please verify the extension is one of the following: png, jpg, jpeg and the file is accessible."
}
Media
Resize an Image
画像をソーシャルメディアのサイズにリサイズ、透かしの追加、切り抜きを行います
POST
/
media
/
resize
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"mediaUrl": "https://img.ayrshare.com/012/gb.jpg", "platform": "instagram"' \
-X POST https://api.ayrshare.com/api/media/resize
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/media/resize", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`
},
body: JSON.stringify({
mediaUrl: "https://img.ayrshare.com/012/gb.jpg", // required
platform: "instagram"
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'mediaUrl': 'https://img.ayrshare.com/012/gb.jpg',
'platforms': 'instagram'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://api.ayrshare.com/api/media/resize',
json=payload,
headers=headers)
print(r.json())
<?php
$curl = curl_init();
$data = array (
"mediaUrl" => "https://img.ayrshare.com/012/gb.jpg",
"platforms" => "instagram"
);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.ayrshare.com/api/media/resize',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer API_KEY',
'Accept-Encoding: gzip'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class AyrshareApiClient
{
private readonly HttpClient _httpClient;
private readonly string _apiKey;
private const string BaseUrl = "https://api.ayrshare.com/api";
public AyrshareApiClient(string apiKey)
{
_apiKey = apiKey ?? throw new ArgumentNullException(nameof(apiKey));
_httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_apiKey}");
}
public async Task<string> ResizeMediaAsync(string mediaUrl, string platform)
{
try
{
var requestData = new
{
mediaUrl = mediaUrl,
platform = platform
};
var content = new StringContent(
JsonSerializer.Serialize(requestData),
Encoding.UTF8,
"application/json"
);
var response = await _httpClient.PostAsync($"{BaseUrl}/media/resize", content);
response.EnsureSuccessStatusCode();
var jsonResponse = await response.Content.ReadAsStringAsync();
return jsonResponse;
}
catch (HttpRequestException ex)
{
throw new Exception($"Failed to resize media: {ex.Message}", ex);
}
}
public void Dispose()
{
_httpClient.Dispose();
}
}
{
"status": "success",
"url": "https://media.ayrshare.com/9abf1426d6ce9122ef11c72bd62e59807c5cc083/8UbyBjHTxgHkAC1I37e6O.jpg",
"platform": "instagram",
"mode": "blur",
"effects": {
"color": "#A020F0"
}
}
{
"action": "resize",
"status": "error",
"code": 312,
"message": "Invalid extension type. Extension: null. Please verify the extension is one of the following: png, jpg, jpeg and the file is accessible."
}
各ソーシャルネットワークにはソーシャルメディア画像の個別要件があります。resize エンドポイントを使用すると、ソーシャルネットワークに準拠した画像サイズを選択したり、透かしを追加したり、背景を変更したり、エフェクトを適用したり、切り抜きを行ったりできます。
既定では、リサイズは画像の寸法を変更しますが、画像の切り抜きは行いません。代わりに切り抜きも可能です。詳細は下記をご覧ください。
Blur 画像の例:
southeast 位置での透かし画像の例:
Color 背景画像の例:
Grayscale 画像の例:
WebP への変換例:
ヘッダーパラメータ
ボディパラメータ
string
必須
リサイズする画像の URL。
https:// で始まる必要があります。array
必須
URL をリサイズするソーシャルメディアプラットフォーム。詳細は platform
options をご覧ください。
object
メディアファイルを multipart form-data オブジェクトとして送信します。
imageUrl がない場合は必須です。string
不透明度や色などを変更します。詳細は effects options
をご覧ください。
object
リサイズ用の
width と height を指定するオブジェクト。切り抜きを行う場合は、任意で中心の x と y 座標を指定できます。
既定は画像の中心です。Dimensions
{
"width": 500,
"height": 500,
"xCoordinate": 35, // optional for crop mode
"yCoordinate": 50 // optional for crop mode
}
プラットフォームが指定されていない場合、width と height は必須です。
boolean
PNG から JPG のように、JPG ファイルに自動変換します。品質は 75% が使用されます。
詳細は convert to a JPG をご覧ください。
boolean
PNG から WebP のように、WebP ファイルに自動変換します。品質は 75% が使用されます。
詳細は convert to a WebP をご覧ください。
プラットフォームオプション
プラットフォームを文字列で指定すると、画像の事前定義された寸法が使用されます。またはdimensions フィールドで独自の寸法を指定できます。
例えば "platform": "facebook" を指定すると、画像の寸法は width 1200px、height 630px に設定されます。
facebook: 幅 1200px、高さ 630px。instagram: 幅 1080px、高さ 1080px。instagram_landscape: 幅 1080px、高さ 680px。instagram_portrait: 幅 1080px、高さ 1920px。instagram_special: 幅 1080px、高さ 800px。linkedin: 幅 1200px、高さ 627px。pinterest: 幅 1080px、高さ 1920px。tiktok: 幅 1080px、高さ 1920px。twitter: 幅 1600px、高さ 900px。
mode パラメータを crop に設定し、dimensions および xCoordinate、yCoordinate フィールドを使用できます。
Mode
Resize
Resize は既定のモードで、アスペクト比を維持しながら画像の寸法を変更します。 コンテンツを切り抜くことなく、指定された寸法に画像をリサイズします。 JSON の例:Resize
{
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
"platform": "instagram",
"mode": "resize"
}
dimensions フィールドを使用してカスタム寸法を指定することもできます。
Resize with Dimensions
{
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
"mode": "resize",
"dimensions": {
"width": 800,
"height": 600
}
}
platform か、dimensions フィールドの width と height のいずれかを指定する必要があります。
Crop
Crop は指定された寸法に画像を「切り抜き」ます。既定では中心座標は画像の中心になります。独自の x/y 座標を指定することもできます。 JSON の例:Crop
{
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
"platform": "instagram",
"mode": "crop"
}
dimensions フィールドを使用してカスタム寸法や任意の切り抜き座標を指定することもできます。
Crop with Dimensions
{
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
"mode": "crop",
"dimensions": {
"width": 1080,
"height": 1080,
"xCoordinate": 35,
"yCoordinate": 50
}
}
platform か、dimensions フィールドの width と height のいずれかを指定する必要があります。
正方形の切り抜きでは、width または height が提供された画像の寸法より小さい場合、width または height の小さい方が使用されます。例えば画像が 1200x800 で、要求された切り抜きが 1080x1080 の場合、返される画像は 800x800 となります。
Blur
Blur エフェクトは画像を背景として複製し、画像をぼかします。 Blur JSON の例:Blur
{
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
"platform": "instagram",
"mode": "blur"
}
Watermark
Watermark 概要
URL(https:// で始まる必要があります)と任意の位置を指定することで、画像に透かしを追加できます。
既定では透かしは画像の右下隅 — southeast — に表示されます。
背景が透明な PNG を推奨します。
Watermark JSON の例:
Watermark
{
"mediaUrl": "https://img.ayrshare.com/random/photo-13.jpg",
"platform": "instagram",
"watermark": {
"url": "https://img.ayrshare.com/012/100-percent.png",
"position": "northeast" // optional
}
}
Watermark 位置
透かしの位置は以下のいずれかを指定できます。northnortheasteastsoutheastsouthsouthwestwestnorthwestcenter
Effects オプション
Color Hexadecimal
Blur の背景色の 16 進数値。"mode": "blur" の場合のみ適用されます。文字列値、例: "#A020F0"
Color 背景 JSON の例:
Color Background
{
"mediaUrl": "https://img.ayrshare.com/012/gb.jpg",
"platform": "instagram",
"mode": "blur",
"effects": {
"color": "#A020F0"
}
}
Color: Grayscale、Sepia、Invert
grayscale、sepia、invert を指定することで、主要な画像の色を変更できます。背景が不要な場合、"blur": true フィールドは必須ではなく、使用すべきではありません。
Grayscale JSON の例:
Grayscale
{
"mediaUrl": "https://img.ayrshare.com/random/photo-13.jpg",
"platform": "instagram",
"effects": {
"color": "grayscale"
}
}
Opacity
画像の不透明度を設定します。数値の範囲: 0〜1。 Opacity JSON の例:Opacity
{
"effects": {
"opacity": 0.2
}
}
Quality
JPG または JEPG 画像の場合、画像の品質(圧縮量)を指定します。 数値が小さいほど圧縮率が高くなり画質が下がります。 数値が大きいほど圧縮率が低くなり画質が上がります。数値の範囲: 0〜100。 Quality JSON の例:Quality
{
"effects": {
"quality": 20
}
}
JPG または WebP への変換
convertToJpg および convertToWebP オプションを使用すると、画像を元のフォーマット(PNG など)からそれぞれ JPG または WebP フォーマットに変換できます。
既定では、変換後の画像の品質設定は 75% となります。
エフェクトオブジェクト内の quality パラメータを使用して圧縮レベルをカスタマイズできます。
ソース画像が既に JPG で convertToJpg を使用する場合、API はフォーマットを変更せずに指定された寸法にリサイズするだけである点にご注意ください。
JPG への変換例:
Convert to JPG
{
"convertToJpg": true
}
Convert to WebP
{
"convertToWebP": true
}
curl \
-H "Authorization: Bearer API_KEY" \
-H 'Content-Type: application/json' \
-d '{"mediaUrl": "https://img.ayrshare.com/012/gb.jpg", "platform": "instagram"' \
-X POST https://api.ayrshare.com/api/media/resize
const API_KEY = "API_KEY";
fetch("https://api.ayrshare.com/api/media/resize", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${API_KEY}`
},
body: JSON.stringify({
mediaUrl: "https://img.ayrshare.com/012/gb.jpg", // required
platform: "instagram"
})
})
.then((res) => res.json())
.then((json) => console.log(json))
.catch(console.error);
import requests
payload = {'mediaUrl': 'https://img.ayrshare.com/012/gb.jpg',
'platforms': 'instagram'}
headers = {'Content-Type': 'application/json',
'Authorization': 'Bearer API_KEY'}
r = requests.post('https://api.ayrshare.com/api/media/resize',
json=payload,
headers=headers)
print(r.json())
<?php
$curl = curl_init();
$data = array (
"mediaUrl" => "https://img.ayrshare.com/012/gb.jpg",
"platforms" => "instagram"
);
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://api.ayrshare.com/api/media/resize',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query($data),
CURLOPT_HTTPHEADER => array(
'Authorization: Bearer API_KEY',
'Accept-Encoding: gzip'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
public class AyrshareApiClient
{
private readonly HttpClient _httpClient;
private readonly string _apiKey;
private const string BaseUrl = "https://api.ayrshare.com/api";
public AyrshareApiClient(string apiKey)
{
_apiKey = apiKey ?? throw new ArgumentNullException(nameof(apiKey));
_httpClient = new HttpClient();
_httpClient.DefaultRequestHeaders.Add("Authorization", $"Bearer {_apiKey}");
}
public async Task<string> ResizeMediaAsync(string mediaUrl, string platform)
{
try
{
var requestData = new
{
mediaUrl = mediaUrl,
platform = platform
};
var content = new StringContent(
JsonSerializer.Serialize(requestData),
Encoding.UTF8,
"application/json"
);
var response = await _httpClient.PostAsync($"{BaseUrl}/media/resize", content);
response.EnsureSuccessStatusCode();
var jsonResponse = await response.Content.ReadAsStringAsync();
return jsonResponse;
}
catch (HttpRequestException ex)
{
throw new Exception($"Failed to resize media: {ex.Message}", ex);
}
}
public void Dispose()
{
_httpClient.Dispose();
}
}
{
"status": "success",
"url": "https://media.ayrshare.com/9abf1426d6ce9122ef11c72bd62e59807c5cc083/8UbyBjHTxgHkAC1I37e6O.jpg",
"platform": "instagram",
"mode": "blur",
"effects": {
"color": "#A020F0"
}
}
{
"action": "resize",
"status": "error",
"code": 312,
"message": "Invalid extension type. Extension: null. Please verify the extension is one of the following: png, jpg, jpeg and the file is accessible."
}