-
Notifications
You must be signed in to change notification settings - Fork 275
Open
Description
Describe the bug
Image rotation (of large dimension images over small angles) suffers from significant inaccuracy.
To Reproduce
<?php
$gd = imagecreatetruecolor(5000,5000);
imagefill($gd, 0, 0, imagecolorallocate($gd, 255, 255, 255));
$rot = deg2rad(-1);
$a = cos($rot);
$b = sin($rot);
$gdAffine = imageaffine($gd, [$a ,$b, -$b, $a, 0, 0]);
ob_start();
imagejpeg($gdAffine);
$jpg = ob_get_clean();
echo '<img src="data:image/jpg;base64,'.base64_encode($jpg).'">';
$gdRotate = imagerotate($gd, rad2deg(-$rot), 0);
ob_start();
imagejpeg($gdRotate);
$jpg = ob_get_clean();
echo '<img src="data:image/jpg;base64,'.base64_encode($jpg).'">';- This rotates a 5000x5000 canvas by 1 degree using both
imageaffineandimagerotate - This should result in a black triangle at the top of the canvas with a height of 5000*sin(1deg) = 87 pixels
- Both methods produce a final canvas of 5087x5087 which is the expected size
imageaffineproduces a triangle of 87px high ✔imagerotateproduces a triangle of 73px high ❌ (this implies an actual rotation of ~0.83 degrees)- Looking to the right hand side of the top of
imagerotateshows substantial clipping, suggesting the image has been scaled up in some way and the edge pixels lost.
Expected Behaviour
imageaffine and imagerotate should produce images of identical rotation, with imagerotate producing a better looking output due to the interpolation method.
Top left of imageaffine followed by top left of imagerotate:
Top right of imageaffine showing pixels correctly go into edge
Top right of imagerotate showing substantial cropping of pixels along edge.
Environment (please complete the following information):
- OS: Rocky, PHP 8.3
- Version: GD 2.3.3
Additional context
I initially posted this as a php/php-src issue
It was suggested there that this is a likely side effect of this issue: #951
Metadata
Metadata
Assignees
Labels
No labels