How to Create a Swirl Distortion Effect in PHP
If you’re interested in creating custom filters for your website’s images — or looking to incorporate a photo-filter workflow for UGC uploads — Swirl Distortion is a great operation to start with. Using the PHP code examples provided below, you can easily implement an API which allows you to customize a Swirl Distortion effect on image uploads (common formats like JPG, PNG supported).
First, let’s run this command to install the SDK:
composer require cloudmersive/cloudmersive_imagerecognition_api_client
After that, let’s copy and paste the code examples below to structure our API call. You’ll have three request parameters to fulfill, including the following:
- Degrees: an integer which determines the intensity of the swirl effect
- Image File: the image file path for the operation
- API Key: to authenticate the operation (get one for free by registering a free account on our website)
<?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\FilterApi(
new GuzzleHttp\Client(),
$config
);
$degrees = 56; // int | Degrees of swirl
$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->filterSwirl($degrees, $image_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling FilterApi->filterSwirl: ', $e->getMessage(), PHP_EOL;
}
?>
That’s all you need to get started filtering your images. Easy!