將前景圖放在背景圖的指定位置
public function combineimg($backimg,$upimg) { $dst_path = $backimg; // 背景圖 $src_path = $upimg; // 前景圖 //創建圖片的實例 $dst = imagecreatefromstring(file_get_contents($dst_path)); $src = imagecreatefromstring(file_get_contents($src_path)); // 把前圖片的白色背景設為透明 imagecolortransparent($src, imagecolorallocate($src, 255, 255, 255)); //獲取水印圖片的寬高 list($src_w, $src_h) = getimagesize($src_path); //將水印圖片復制到目標圖片上 imagecopymerge($dst, $src, 235, 720, 0, 0, $src_w, $src_h, 100); $newpath = IA_ROOT."/attachment/"; //生成圖片 imagepng($dst,$newpath.'test2.png');//銷毀 imagedestroy($dst); imagedestroy($src); return $res='test2.png'; }