How to Add Drop Shadows to Images in PHP

Cloudmersive
2 min readMar 3, 2023

--

While digital content fundamentally resides in a two-dimensional medium, it’s still possible to create a three-dimensional illusion with artful shadowing. With the complementary, ready-to-run PHP code examples provided below, you can quickly implement a Drop Shadow feature for your applications and customize images with ease.

First, you’ll need to install the SDK — you can run this command:

composer require cloudmersive/cloudmersive_imagerecognition_api_client

Next, copy in the below code to complete your API call. Each request will need to include an API key (get one for free by registering a free account here) along with integers specifying the X & Y offset, sigma and opacity of the drop shadow:

<?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\EditApi(


new GuzzleHttp\Client(),
$config
);
$x = 56; // int | Horizontal (X) offset of the drop shadow
$y = 56; // int | Vertical (Y) offset of the drop shadow
$sigma = 56; // int | Sigma (blur distance) of the drop shadow
$opacity = 56; // int | Opacity of the drop shadow; 0 is 0% and 100 is 100%
$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->editDropShadow($x, $y, $sigma, $opacity, $image_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling EditApi->editDropShadow: ', $e->getMessage(), PHP_EOL;
}
?>

Just like that, you have a new, low-code image editing feature for your PHP applications.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

No responses yet