[ 'User-Agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.109 Safari/537.36', 'Referer' => $host, // 'cookies' => $cookieJar ]]); $fileParts = pathinfo($imageUrl); $completeFile = $dir . "/" . $albumName . "-" . $fileParts["filename"] . "." . $fileParts["extension"]; $client->request('GET', $imageUrl, ['sink' => $completeFile]); } public static function mergeImage($path, $picList) { $imgInfo = array();//图片信息 $tmp = 1; $width = 720;//生成的图像宽度 $picCount = count($picList);//图片总数 $imgInfo['width'] = $width; $imgInfo['height'] = 0; //首先等比例缩放,让所有图片宽度一样,计算出图片等比例缩放后的长和宽 for ($i = 0; $i < $picCount; $i++) { usleep(100); $imgInfo[$i]['url'] = $picList[$i]['src']; $imgInfo[$i] = getimagesize($imgInfo[$i]['url']); $tmp = ($imgInfo[$i][0]) / $width; $imgInfo[$i]['width'] = $width; $imgInfo[$i]['height'] = ($imgInfo[$i][1]) / $tmp; $imgInfo[$i]['url'] = $picList[$i]['src']; $imgInfo[$i]['x'] = 0; $imgInfo[$i]['y'] = $imgInfo['height']; $imgInfo['height'] += $imgInfo[$i]['height']; } $new_img = ImageCreateTrueColor($imgInfo['width'], $imgInfo['height']); // 创建一个画布,作为拼接后的图片 for ($i = 0; $i < $picCount; $i++) { usleep(100); //以下的三行代码 缩放原图 $img_r = imagecreatefromjpeg($imgInfo[$i]['url']); // 获取原图 $dst_r = ImageCreateTrueColor($imgInfo[$i]['width'], $imgInfo[$i]['height']); // 获取新图 imagecopyresampled($dst_r, $img_r, 0, 0, 0, 0, $imgInfo[$i]['width'], $imgInfo[$i]['height'], $imgInfo[$i][0], $imgInfo[$i][1]); //把缩放后的图片放在画布上 imagecopyresampled($new_img, $dst_r, $imgInfo[$i]['x'], $imgInfo[$i]['y'], 0, 0, $imgInfo['width'], $imgInfo[$i]['height'], $imgInfo[$i]['width'], $imgInfo[$i]['height']); imagedestroy($dst_r);//销毁掉缩放的图片 } //获取时间戳,以时间戳的名字存放 $name = strval(time()); $img_path = $path . $name . ".jpg"; //存放拼接后的图片到本地 imagejpeg($new_img, $img_path); } }