Skip to content

Commit d9cddc7

Browse files
authored
Merge pull request #11 from 21stdigital/feat/set-default-focus-params
feat: mimic glide's default cropping settings
2 parents 9112a11 + 015e3da commit d9cddc7

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/Converter/CloudinaryConverter.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ private function hasCombinedManipulationParams()
226226
private function getMetaParams($item)
227227
{
228228
$params = collect();
229+
$manipulation_params = $this->getManipulationParams($item);
229230

230231
// Set focus related parameters.
231232
if ($item->get('focus')) {
@@ -235,6 +236,20 @@ private function getMetaParams($item)
235236
$y = floor(($y_percentage / 100) * $this->getOriginalHeight($item));
236237
$zoom = floor($zoom * 10) / 10;
237238

239+
$params->put('x', $x);
240+
$params->put('y', $y);
241+
$params->put('zoom', $zoom);
242+
$params->put('gravity', 'xy_center');
243+
} else if ($manipulation_params->has('crop') && $manipulation_params->get('crop') === 'fill') {
244+
/**
245+
* When using `fit="crop_focal"` in statamic and NOT defining a focal point, the asset is cropped by glide from the center point.
246+
* In contrary, when using cloudinary, this is not the case.
247+
* The following code replicates this behavior.
248+
*/
249+
$x = floor(0.5 * $this->getOriginalWidth($item));
250+
$y = floor(0.5 * $this->getOriginalHeight($item));
251+
$zoom = 1;
252+
238253
$params->put('x', $x);
239254
$params->put('y', $y);
240255
$params->put('zoom', $zoom);

0 commit comments

Comments
 (0)