SDKs overview

ReSmush.it provides tools to integrate its image optimization service into various development environments. The core offering includes a RESTful API for direct programmatic interaction, primarily supported by an official PHP library. This library assists developers in sending images for compression and retrieving optimized versions, handling the underlying HTTP requests and responses ReSmush.it API documentation. Beyond the official support, the developer community has contributed various libraries and wrappers, extending ReSmush.it's utility across different programming languages and platforms. These community efforts aim to simplify API consumption, abstracting the complexities of HTTP requests, authentication (if applicable), and response parsing, enabling quicker integration into diverse projects.

The SDKs and libraries are designed to facilitate common image optimization workflows, such as uploading images from local storage or remote URLs, specifying compression quality (though ReSmush.it primarily uses a default optimal setting for its free tier), and handling asynchronous processing. Developers can use these tools to automate image compression, which is a critical component for improving website load times and overall user experience, as highlighted by web performance best practices like those recommended by Google's Core Web Vitals Google PageSpeed Insights guide. Integrating these tools allows for dynamic image processing, ensuring that images served to end-users are optimized without manual intervention.

Official SDKs by language

ReSmush.it offers an official SDK primarily for PHP, reflecting its strong integration with the WordPress ecosystem where PHP is the dominant language. This official library streamlines the process of sending image data to the ReSmush.it API and receiving the compressed output. The library typically manages API endpoint construction, request headers, and response parsing, reducing the boilerplate code developers need to write.

Language Package/Library Name Installation Command Maturity/Status
PHP resmushit/resmushit-api-client composer require resmushit/resmushit-api-client Official, Actively Maintained

The PHP client is maintained by the ReSmush.it team to ensure compatibility with the latest API versions and provide consistent performance. It is the recommended approach for PHP-based applications seeking to integrate ReSmush.it's services directly, especially for custom WordPress plugin development or standalone PHP projects requiring image optimization capabilities ReSmush.it API documentation. The official client is designed to handle various image formats supported by the API, including JPEG, PNG, and GIF, and manage the specific parameters required for each request.

Installation

Installing the ReSmush.it PHP SDK typically involves using Composer, the dependency manager for PHP. This method ensures that all necessary dependencies are resolved and installed correctly, making the library ready for use in a PHP project.

PHP SDK Installation (Composer)

  1. Prerequisites: Ensure Composer is installed on your development machine. If not, follow the Composer installation instructions.
  2. Create a Project (if needed): Navigate to your project directory. If starting a new PHP project, you might initialize a composer.json file.
  3. Install the Library: Open your terminal or command prompt, navigate to your project's root directory, and execute the following command:
composer require resmushit/resmushit-api-client

This command downloads the resmushit/resmushit-api-client package and its dependencies into your project's vendor/ directory and updates your composer.json and composer.lock files accordingly. Once installed, you can include Composer's autoloader in your PHP scripts to make the library classes available.

require 'vendor/autoload.php';

use ReSmushIt\ResmushIt;
// Your code here

For projects not using Composer, manual installation would involve downloading the library files and managing class loading, which is generally discouraged for modern PHP development due to complexity in dependency management. Composer provides a standardized and efficient way to manage external libraries.

Quickstart example

This quickstart demonstrates how to use the official ReSmush.it PHP SDK to optimize an image from a URL. This example assumes the PHP SDK has been installed via Composer.

PHP Image Optimization from URL

<?php

require 'vendor/autoload.php';

use ReSmushIt\ResmushIt;

// Instantiate the ResmushIt client
// No API key is required for the free tier, but you might pass configuration for enterprise plans.
$resmushit = new ResmushIt();

// Define the URL of the image to optimize
$imageUrl = 'https://www.example.com/path/to/your/image.jpg';

// Define the desired quality (0-100, 100 for best quality, higher compression at lower values)
// ReSmush.it's free tier typically applies optimal compression by default, 
// but this parameter can be used if supported for custom plans.
$quality = 80; // Example quality setting

try {
    // Optimize the image from the URL
    $result = $resmushit->smushImage(['src' => $imageUrl, 'qlty' => $quality]);

    // Check if optimization was successful
    if (isset($result['success']) && $result['success'] === true) {
        echo "Image optimized successfully!\n";
        echo "Original size: " . $result['src_size'] . " bytes\n";
        echo "Optimized size: " . $result['dest_size'] . " bytes\n";
        echo "Savings: " . $result['percent'] . "%\n";
        echo "Optimized image URL: " . $result['dest'] . "\n";

        // You can now download the optimized image from $result['dest']
        // For example, using file_get_contents and file_put_contents
        // $optimizedImageData = file_get_contents($result['dest']);
        // file_put_contents('optimized_image.jpg', $optimizedImageData);
        // echo "Optimized image saved as optimized_image.jpg\n";

    } else {
        echo "Image optimization failed.\n";
        if (isset($result['error'])) {
            echo "Error: " . $result['error'] . "\n";
        } else {
            echo "Unknown error.\n";
        }
    }
} catch (Exception $e) {
    echo "An error occurred: " . $e->getMessage() . "\n";
}

?>

This snippet initializes the ResmushIt client, specifies an image URL and a quality setting (though the free tier's quality is often predetermined for optimal results), and then calls the smushImage method. The response contains details about the original and optimized image sizes, the percentage saved, and a URL to the compressed image. Developers can then download this optimized image for storage or immediate use.

For local file uploads, the smushImage method can also accept a file path or binary data, depending on the specific implementation of the SDK. Refer to the ReSmush.it comprehensive API documentation for full details on all available parameters and methods for different optimization scenarios, including handling different image formats and error responses.

Community libraries

While ReSmush.it primarily supports PHP with an official SDK, the broader developer community has created wrappers and integrations for other programming languages and environments. These community-driven projects aim to make the ReSmush.it API accessible to developers working in different tech stacks.

Examples of Community Contributions (Illustrative)

  • Python Wrappers: Developers have created Python libraries that encapsulate the ReSmush.it API calls, allowing Python applications to easily send images for compression. These often use standard HTTP libraries like requests to interact with the API endpoints. A typical Python wrapper would provide methods for uploading local files or specifying image URLs and handling the JSON response.
  • Node.js Modules: For JavaScript environments, Node.js modules exist that provide similar functionality. These modules leverage Node.js's asynchronous capabilities to handle image uploads and downloads efficiently, making them suitable for web servers or build processes that require image optimization.
  • Ruby Gems: Ruby developers might find gems that wrap the ReSmush.it API, integrating seamlessly into Ruby on Rails or other Ruby applications. These often prioritize convention over configuration, providing an idiomatic Ruby interface to the API.
  • Go Packages: In the Go ecosystem, community packages can offer strong typing and concurrency features to interact with the ReSmush.it API. These are typically used in high-performance backend services where efficient image processing is crucial.

The availability and maintenance status of community libraries can vary significantly. Developers interested in using ReSmush.it with a language other than PHP should search platforms like GitHub, npm, PyPI, or RubyGems for existing community-contributed libraries. It's recommended to review the project's activity, documentation, and open issues to assess its reliability and suitability for a production environment. Always verify the source and ensure any third-party library adheres to security best practices. The ReSmush.it API reference remains the ultimate source of truth for API endpoint specifications, regardless of the client library used.