How to Convert Images to Bitmap BMP Format using PHP
High quality, uncompressed image formats are extremely useful when we want to make complex changes to our images, particularly in image editing software. Thankfully, using the below code, you can easily take advantage of an image conversion API which will convert dozens of common image formats to Bitmap at scale. Just copy and paste from the ready-to-run PHP examples provided, include a free-tier API key with your request (you can get one by registering a free account here), and you’re all done.
Our first step is to install the SDK using the below command:
composer require cloudmersive/cloudmersive_imagerecognition_api_client
Next, we can complete our API call using the remaining code examples:
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\ConvertApi(
new GuzzleHttp\Client(),
$config
);
$image_file = "/path/to/inputfile"; // \SplFileObject | Image file to perform the operation on. Common file formats such as PNG, JPEG are supported.
try {
$result = $apiInstance->convertToBmp($image_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertApi->convertToBmp: ', $e->getMessage(), PHP_EOL;
}
?>
Just like that, we’re all done!
With your free-tier API key, you’ll get a limit of up to 800 API calls per month, and you won’t need to worry about any additional commitments — once your limit is reached, that total will reset for the following month. You can easily upgrade to enterprise level accounts if/when the need arises.