1. 程式人生 > >PHP合併兩張圖片的實現

PHP合併兩張圖片的實現

程式碼如下:

$bigImgPath = "./images/bg.jpg";
$qCodePath = "./images/thumb/$id.jpg";

$bigImg = imagecreatefromstring(file_get_contents($bigImgPath));
$qCodeImg = imagecreatefromstring(file_get_contents($qCodePath));

list($qCodeWidth, $qCodeHight, $qCodeType) = getimagesize($qCodePath);

imagecopymerge($bigImg, $qCodeImg, 239, 677, 0, 0, $qCodeWidth, $qCodeHight, 100);
 
list($bigWidth, $bigHight, $bigType) = getimagesize($bigImgPath);

imagejpeg($bigImg,'./images/'.$id.'.jpg');

imagejpeg輸出圖片,並儲存。