PHP function imagecopy centered

The default location for the imagecopy function is left-top.

imagecopy (resource dst_im, resource src_im, int dst_x, int dst_y, int src_x, int src_y, int src_w, int src_h)

How can I make it always overlap in the center for images of any size?


Answer 1, authority 100%

not left-top, but you set the coordinates yourself.

for example, we have a 10×20 image, and we need to place it on a 20×40 image

imagecopy ($img_20x20, $img_10x10, round((20-10)/2), round((40-20)/2), 0, 0, 10, 20);