Intervention / image

PHP Image Processing
https://image.intervention.io
MIT License
13.88k stars 1.5k forks source link

Cover resizing is incorrect #1359

Closed btamas86 closed 4 months ago

btamas86 commented 4 months ago

Describe the bug I use the "cover" type of resizing and I noticed that if the original image is odd in size, the resizing is incorrect.

Original image size: 375x250 Requested size: 240x90 Received size: 239x90

So it is rounded down, not up, which I think is a problem.

Code Example

$imageContent = file_get_contents('image.jpg');
$image = (new Intervention\Image\ImageManager(new Intervention\Image\Drivers\Gd\Driver))->read($imageContent);
$image->cover(240, 90, 'center');
$imgEncoded = $image->encodeByMediaType(quality: 85);

response((string)$imgEncoded)
    ->withHeaders([
        'Content-type' => $imgEncoded->mediaType(),
    ]);

Images Original: 4k-wallpaper-background-beautiful-853199-horizontal Resized:

image

Environment (please complete the following information):

olivervogel commented 4 months ago

Thanks for reporting. Yes, I can confirm the bug. Unfortunately it happens with GD and Imagick. I will look into it.

btamas86 commented 4 months ago

Thank you very much!

olivervogel commented 4 months ago

This is now fixed in 3.6.5.