如何使用https://graph.facebook.com/744595326681559/picture?width=720&;height=720
作为图层?
<?php
$bgFile = __DIR__ . "/background-layer-1.png"; // 93 x 93
$imageFile = __DIR__ . "/icon-layer-2.png"; // 76 x 76
$watermarkFile = ('https://graph.facebook.com/744595326681559/picture?width=720&;height=720');
// We want our final image to be 76x76 size
$x = $y = 240;
// dimensions of the final image
$final_img = imagecreatetruecolor($x, $y);
// Create our image resources from the files
$image_1 = imagecreatefrompng($bgFile);
$image_2 = imagecreatefrompng($imageFile);
$image_3 = imagecreatefrompng($watermarkFile);
// Enable blend mode and save full alpha channel
imagealphablending($final_img, true);
imagesavealpha($final_img, true);
// Copy our image onto our $final_img
imagecopy($final_img, $image_1, 0, 0, 0, 0, $x, $y);
imagecopy($final_img, $image_2, 0, 0, 0, 0, $x, $y);
imagecopy($final_img, $image_3, 0, 0, 0, 0, $x, $y);
ob_start();
imagepng($final_img);
$watermarkedImg = ob_get_contents(); // Capture the output
ob_end_clean(); // Clear the output buffer
header('Content-Type: image/png');
echo $watermarkedImg; // outputs: `http://i.imgur.com/f7UWKA8.png`
imagepng($final_img, 'final_img1.png');
1条答案
按热度按时间fjnneemd1#
在使用imagecreatefrompng创建Facebook个人资料图片时,有两个问题。(如果不是,它将失败),其次,使用imagecreatefrom函数加载网络资源的一个陷阱是,它不会遵循任何重定向。Facebook 301重定向到一个更长的URL,所以这不会被选中。我的建议是使用cURL从Facebook获取图像数据并使用它。
类似于:
我不完全相信输出是你所期望的,所以请随时澄清你的需要,我会尽我所能。