Optimize image Documentation

Optimize Image API Documentation

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.

Endpoint

GET https://codefusiononline.com/optimize-image

Query Parameters

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

Example Request URL

https://codefusiononline.com/optimize-image?imageUrl=https://codefusiononline.com/yourimage.jpg&width=400&height=300&format=webp&quality=80

Response Codes

  • 200 OK - Returns the optimized image.
  • 400 Bad Request - Error if the domain is not registered.
  • 500 Internal Server Error - Error if there is an issue with image processing.

Example Code

1. WordPress HTTP Request (wp_remote_get)


// 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
}

2. PHP cURL Request


// 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);

3. Laravel HTTP Request


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());
}

4. JavaScript Fetch API


// 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));

Call To Action

But pain in reproach in pleasure wants to be a cillum pain eu flees no birth. Excepteur are blinding desires do not proident, are in fault who desert offices softens the soul that is labor.

Call To Action

Contact

His needs result from something escape him indeed are consectetur will

Contact Info

Praesent sapien massa, vallis a pellentesque nec, egestas non nisi. Vestibulum ante ipsum primis.

Our Location

CodeFusionOnline

Rajasthan, Bagar 333023

Phone Number

+91 8239 724704

Get In Touch

Praesent sapien massa, vallis a pellentesque nec, egestas non nisi. Vestibulum ante ipsum primis.

Loading
Your message has been sent. Thank you!