#php #image #rotation
#php #изображение #поворот
Вопрос:
Прямо сейчас мое повернутое изображение выравнивается слева и сверху от моего целевого изображения. Я хочу, чтобы центр повернутого изображения был центрирован на целевом изображении. Степень поворота является динамической. $ center_pt — это центральная точка моего назначения. Я искал в Интернете полтора дня, но должен быть способ!
$destination_image = 960; //960px x 960px
rotated image = 640px x 640px; // ($rotate amp; $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);
Извините, я подготовил изображение, чтобы поделиться с вами, но у меня не было достаточной репутации, чтобы опубликовать его.
Ответ №1:
Было трудно понять, как центрировать мое изображение после его поворота, потому что оно продолжало выравниваться влево. Вот что я сделал, после удаления более подробного решения, работает идеально!
$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