$headimgurl = 'https://XXX.png';
$headimg = imagecreatefromstring(file_get_contents($headimgurl));
$imageSize = 460;
$resizedImage = imagescale($headimg,$imageSize,$imageSize);
$bg_img = '/static/images/poster_2.png';
$bg_img = imagecreatefromstring(file_get_contents($bg_img));
$new_img = $this->addRoundedCorners($resizedImage,$bg_img);
function addRoundedCorners($inputFile,$bg_img) {
$image = $inputFile;
$w = imagesx($image);
$h = imagesy($image);
$w = min($w, $h);
$h = $w;
imagesavealpha($bg_img, true);
$r = $w / 2;
for ($x = 0; $x < $w; $x++) {
for ($y = 0; $y < $h; $y++) {
$rgbColor = imagecolorat($image, $x, $y);
if (((($x - $r) * ($x - $r) + ($y - $r) * ($y - $r)) < ($r * $r))) {
imagesetpixel($bg_img, $x+310, $y+515, $rgbColor);
}
}
}
return $bg_img;
}