I have registered a thumb component where I intend to manipulate the crop function.
The crop function is dependent on the dimensions class and all the output of every function is stored there as well. Because I want to make the crop outside of the dimensions class I need some way to still return the data to the dimensions object.
I have a code snippet below where I try to show some things.
- I commented what
$dimensions
returns, a Dimension object - I made a custom array. If it’s possible to convert somehow and return it to the dimensions object, it’s good enough.
- I have a comment about what I have in mind for my final output. (may not be that important)
- I have a comment about the crop conversion (may not be that important).
(I also have another file to register this function as a plugin)
use Thumb as Generator;
class MyThumbClass extends Kirby\Component\Thumb {
protected function dimensions(Generator $thumb) {
$dimensions = clone $thumb->source->dimensions();
if(isset($thumb->options['crop'])) {
if($thumb->options['crop'] === true) {
$dimensions->crop(a::get($thumb->options, 'width'), a::get($thumb->options, 'height'));
print_r($dimensions);
/*
Dimensions Object
(
[width] => 400
[height] => 400
[ratio] => 1
[orientation] => square
)
*/
$array = [
'width' => 300,
'height' => 300,
'ratio' => 1,
'orentation' => 'square'
];
// Convert to Dimensions Object
}
} else {
$dimensions->resize(a::get($thumb->options, 'width'), a::get($thumb->options, 'height'), a::get($thumb->options, 'upscale'));
}
/*
echo thumb($image, array('width' => 400, 'height' => 250, 'crop' => 'top left'));
*/
/*
$image = new abeautifulsite\SimpleImage( $image_or_thumb_path );
$image->crop(0, 0, 580, 280);
$image->save( $new_thumb_path );
*/
return $dimensions;
}
}