Ok, I am a little bit confused on where I should applying my cropping logic and implementing srcset, maybe someone could help me out here.
I have images in the panel with the default image block with cropping
My image.php file I have some logic to check if the image is cropped or not and output the correct ratio size but I am not sure if I am doing this is the right location or if this is something that should be happening in my config file, especially if I have instances where I would like to use srcset or thumbs.
<?php
$image = $block->image()->toFile();
$imageWidth = $image->width();
$imageHeight = $image->height();
$ratio = $block->ratio();
list($targetWidth, $targetHeight) = explode('/', $ratio);
$targetRatio = $targetWidth / $targetHeight;
if ($block->crop()->isTrue()) {
if ($imageWidth / $imageHeight > $targetRatio) {
$newHeight = $imageHeight;
$newWidth = (int) ($imageHeight * $targetRatio);
} else {
$newWidth = $imageWidth;
$newHeight = (int) ($imageWidth / $targetRatio);
}
$imageCrop = $image->crop($newWidth, $newHeight);
}
?>
<?= $imageCrop ?>