Image to Image in PHP

This page describes how to convert between images formats in PHP using the cloud-based Pdfcrowd API. The API is easy to use and it takes only a few of lines of code to integrate it to your application.

Installation

The PHP API client library provides easy access to the Pdfcrowd API. No third-party libraries are required.

Download pdfcrowd-5.9.0-php.zip, unzip it and require pdfcrowd.php in your code.

We also offer other installation options such as Composer or GitHub.

Authentication

The credentials to access the API are your Pdfcrowd username and the API key.

API Method Reference

Refer to the Image to Image PHP Reference for a description of all API methods.

Code Examples

Here are a few PHP examples to get you started quickly with the API. See more examples.

<?php
require "pdfcrowd.php";

try
{
    // create the API client instance
    $client = new \Pdfcrowd\ImageToImageClient("your_username", "your_apikey");

    // configure the conversion
    $client->setOutputFormat("jpg");

    // run the conversion and write the result to a file
    $client->convertFileToFile("/path/to/logo.png", "logo.jpg");
}
catch(\Pdfcrowd\Error $why)
{
    // report the error
    error_log("Pdfcrowd Error: {$why}\n");

    // rethrow or handle the exception
    throw $why;
}

?>
<?php
require "pdfcrowd.php";

try
{
    // create the API client instance
    $client = new \Pdfcrowd\ImageToImageClient("your_username", "your_apikey");

    // configure the conversion
    $client->setOutputFormat("jpg");

    // run the conversion and write the result to a file
    $client->convertUrlToFile("https://pdfcrowd.com/static/images/logo.png", "logo.jpg");
}
catch(\Pdfcrowd\Error $why)
{
    // report the error
    error_log("Pdfcrowd Error: {$why}\n");

    // rethrow or handle the exception
    throw $why;
}

?>
<?php
require "pdfcrowd.php";

try
{
    // create the API client instance
    $client = new \Pdfcrowd\ImageToImageClient("your_username", "your_apikey");

    // configure the conversion
    $client->setOutputFormat("jpg");

    // run the conversion and write the result to a file
    $client->convertRawDataToFile(file_get_contents("/path/to/logo.png"), "logo.jpg");
}
catch(\Pdfcrowd\Error $why)
{
    // report the error
    error_log("Pdfcrowd Error: {$why}\n");

    // rethrow or handle the exception
    throw $why;
}

?>

Troubleshooting