image
image copied to clipboard
Using resize() and getSize() to get image dimensions without computing the resulting image
Hello, in my use case i want to know the resulting image dimensions without generating them ahead of time.
I believe "getSize()" should be documented as an API function as its provides valuable information
Here is a example for anyone interested in calculating output dimensions without actually resizing the image
ImageManagerStatic::configure(['driver' => 'imagick']);
$img = ImageManagerStatic::make('path');
$sizes = $img->getSize()->resize(1000,1000, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});
// Even faster without parsing the image if you know original's w,h
$sizes = ImageManagerStatic::canvas($w,$h)->getSize()->resize($maxW,$maxH, function ($constraint) {
$constraint->aspectRatio();
$constraint->upsize();
});