image icon indicating copy to clipboard operation
image copied to clipboard

Using resize() and getSize() to get image dimensions without computing the resulting image

Open marios88 opened this issue 1 year ago • 0 comments

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();
        });

marios88 avatar Nov 15 '23 12:11 marios88