图像旋转,然后与目标图像的中心对齐


Imagerotate and then align with center of destination image

现在我旋转的图像被对齐到我的目标图像的左侧和顶部。我想要的行为是让旋转图像的中心位于目标图像的中心。旋转的程度是动态的。$center_pt是目的地的中心点。我已经在网上找了一天半了,但一定有办法!

$destination_image = 960; //960px x 960px
rotated image = 640px x 640px; // ($rotate & $rotate_me, same thing)
$center_pt = center of destination image
$rotate_me = imagecreatefrompng("myimage.png"); 
$rotate = imagerotate($rotate_me, $dynamicdegree),0);
imagesettile($im, $rotate);
imagefilledellipse($destination_image, $center_pt, $center_pt, $outer_outer_diameter, $outer_outer_diameter,     IMG_COLOR_TILED);

对不起,我准备了一张图片与你分享,但没有足够的信誉来发布它。

这是很难弄清楚如何居中我的图像旋转后,因为它一直对齐到左边。下面是我所做的,在剥离了一个更繁琐的解决方案之后,效果非常好!

  $src = imagerotate($rotate,$yournumber,$transColor); //rotated my image
  imagesavealpha($src, true); // alpha thing otherwise there was a black polygon around image
  //the rotation makes your image bigger, usually, so you need to find the new width and height
  $src_x = ImageSX($src); //find out new x width
  $src_y = ImageSY($src); //find out new y height
  $wantedWidth = 640;  //this is the width I want my completed image to be
  $wantedHeight = 640; //this is the height I want my completed image to be
  $src_widthx = $src_x/2 - $wantedWidth/2;  // divide each by 2 and then subtract desired end width from wider rotated width
  $src_heighty = $src_y/2 - $wantedHeight/2;  // and again for height
imagecopy($im, $src, 0, 0, $src_widthx, $src_heighty, 640, 640);  //notice I'm no longer using imagefilledellipse here as imagecopy seems to be more specifically for centering things