The /optimize-image
endpoint allows you to download, resize, and optimize images from a URL. The endpoint supports various formats (e.g., png, jpg, webp, svg) and provides options for resizing and quality adjustments.
GET https://codefusiononline.com/optimize-image
Parameter | Type | Description | Required | Default |
---|---|---|---|---|
imageUrl |
string | The URL of the image to be processed. | Yes | N/A |
format |
string | The output format (e.g., png, jpg, webp, svg). | No | png |
width |
number | The width to resize the image to. | No | N/A |
height |
number | The height to resize the image to. | No | N/A |
quality |
number | The quality of the output image (1–100). | No | 80 |
https://codefusiononline.com/optimize-image?imageUrl=https://codefusiononline.com/yourimage.jpg&width=400&height=300&format=webp&quality=80
// WordPress wp_remote_get example
$url = 'https://codefusiononline.com/optimize-image';
$args = [
'method' => 'GET',
'body' => [
'imageUrl' => 'https://codefusiononline.com/yourimage.jpg',
'width' => 400,
'height' => 300,
'format' => 'webp',
'quality' => 80,
],
];
$response = wp_remote_get(add_query_arg($args['body'], $url));
if (is_wp_error($response)) {
error_log('Error fetching image: ' . $response->get_error_message());
} else {
$body = wp_remote_retrieve_body($response);
// Process the image data
}
// PHP cURL example
$url = 'https://codefusiononline.com/optimize-image';
$queryParams = http_build_query([
'imageUrl' => 'https://codefusiononline.com/yourimage.jpg',
'width' => 400,
'height' => 300,
'format' => 'webp',
'quality' => 80,
]);
$ch = curl_init("$url?$queryParams");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
} else {
// Process the image data
file_put_contents('optimized_image.webp', $response);
}
curl_close($ch);
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Storage;
$response = Http::get('https://codefusiononline.com/optimize-image', [
'imageUrl' => 'https://codefusiononline.com/yourimage.jpg',
'width' => 400,
'height' => 300,
'format' => 'webp',
'quality' => 80,
]);
if ($response->successful()) {
Storage::put('optimized_image.webp', $response->body());
} else {
logger('Image optimization failed', $response->json());
}
// JavaScript Fetch example
const params = new URLSearchParams({
imageUrl: 'https://codefusiononline.com/yourimage.jpg',
width: 400,
height: 300,
format: 'webp',
quality: 80,
}).toString();
fetch(`https://codefusiononline.com/optimize-image?${params}`)
.then(response => response.blob())
.then(blob => {
const url = URL.createObjectURL(blob);
const img = document.createElement('img');
img.src = url;
document.body.appendChild(img); // Display the image in the browser
})
.catch(error => console.error('Error fetching optimized image:', error));