the solution above calculate mathematically the new [left,bottom] corner used to draw the image, but occurred some problem during the generation of this point because, the image center [x1,y1] do not the same at after, because some strange translation occurred during the image draw:
turn into consideration [x0,y0] the [left,bottom] corner, [x1,y1] the image center, [x2,y2] the image center point before rotation and [xr,yr] the new [left,bottom] corner
$x0 = $left;
$x1 = $x0 + $width/2.0;
$y0 = $bottom;
$y1 = $y0 + $height/2.0;
$x2 = ($x1 - $x0)*cos($alpha) - ($y1 - $y0)*sin($alpha) + $x0;
$dx = $x2 - $x1;
$y2 = ($x1 - $x0)*sin($alpha) + ($y1 - $y0)*cos($alpha) + $y0;
$dy = $y2 - $y1;
$xr = $x0 - $dx;
$yr = $y0 - $dy;
If yout try translate de image center to [0,0] and rotate using this other code:
$x0 = $left;
$x1 = $x0 + $width/2.0;
$y0 = $bottom;
$y1 = $y0 + $height/2.0;
$xr = ($x0 - $x1)*cos($alpha) - ($y0 - $y1)*sin($alpha) + $x1;
$yr = ($x0 - $x1)*sin($alpha) + ($y0 - $y1)*cos($alpha) + $y1;
the same result is showed.
I do not know how the cause of this problem. Some body help, please!