用php实现最近很火的国旗水印头像

Jason
2021-10-02 / 0 评论 / 34 阅读 / 正在检测是否收录...

<?php
if(isset($_GET["qq"])){  //判断qq字段是否存在
  $qq = $_GET["qq"];
  ini_set('default_socket_timeout', 1);  //将file_get_contents()设置超时
  $guoqi_path = "./qqAvg/国旗1024.png";  //水印路径
  $qq_path = "http://q1.qlogo.cn/g?b=qq&nk=" . $qq . "&s=640";
  list($qq_w, $qq_h) = getimagesize($qq_path);
  list($guoqi_w, $guoqi_h) = getimagesize($guoqi_path);
  $nqqavg = imagecreatetruecolor($qq_w, $qq_w);
  $color=imagecolorallocate($nqqavg,255,255,255);
  imagecolortransparent($nqqavg,$color);
  imagefill($nqqavg,0,0,$color);
  $qqavg = imagecreatefromstring(file_get_contents($qq_path));  //获取qq头像并创建图片
  $guoqi = imagecreatefromstring(file_get_contents($guoqi_path));  //获取国旗水印并创建图片
  imagecopy($nqqavg, $qqavg, 0, 0, 0, 0, $qq_w, $qq_h);  //此举是为了如果有透明头像就加上白色背景
  imagecopyresampled($nqqavg, $guoqi, 0, 0, 0, 0, $qq_w, $qq_h, $guoqi_w, $guoqi_h);  //同比例缩小国旗水印跟qq头像大小一致并覆盖
  header('Content-Type: image/jpeg');
  imagejpeg($nqqavg);
  imagedestroy($qqavg);
  imagedestroy($guoqi);
}
?>

0

评论 (0)

取消