2

Pdflib rotates objects like images or texts currently around bottom left. Its possible rotate objects around center?

I tried position={center} option for image objects:

$pdf->fit_image($image, $x, $y, 'fitmethod=meet boxsize={'.$w.' '.$h.'} rotate='.($deg).' position={center}')

and calculate x,y coordinates for text objects:

$cx = $x + ($w / 2);
$cy = $y + ($h / 2);
$theta = $deg * pi() / 180;
$rx = $x * cos($theta) - $y * sin($theta);
$ry = $x * sin($theta) + $y * cos($theta);
$y = $ry + $cy;
$x = $rx + $cx;
Mr.K
  • 21
  • 2

1 Answers1

0

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!