现在,我的旋转图像在我的目标图像的左侧和顶部被对齐。我想要的行为是旋转图像的中心在目标图像上居中。旋转程度是动态的。 $ 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);
抱歉,我准备了一张图片与您分享,但没有足够的声誉发布。
答案 0 :(得分:0)
很难弄清楚如何在旋转之后将图像居中,因为它一直向右对齐。这是我所做的,在删除一个更详细的解决方案后,工作完美!
$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