How to convert HEIC to PNG in PHP
1 min readJul 3, 2019
First, we want to add a reference to our composer.json:
"require": {
"cloudmersive/cloudmersive_document_convert_api_client": "^1.4",
}
Now, all we need to do is call convertImageImageFormatConvert and pass in “HEIC” as the input file format and “PNG” as the output file format:
<?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\ConvertImageApi(
new GuzzleHttp\Client(),
$config
);
$format1 = "HEIC";
$format2 = "PNG";
$input_file = "/path/to/file.heic"; // \SplFileObject | Input file to perform the operation on.try {
$result = $apiInstance->convertImageImageFormatConvert($format1, $format2, $input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ConvertImageApi->convertImageImageFormatConvert: ', $e->getMessage(), PHP_EOL;
}
?>
That’s it! It was that easy to convert the HEIC file to PNG in PHP!