使用 php 对图像加水印,完整代码在这里 =)
O 编写此代码以将 1 个图像覆盖在另一个图像上...出于某种原因,firefox 报告图像中存在错误并且无法显示。
有什么线索吗?
// yeah.php
error_reporting(E_ALL);
// A FUNCTION TO ADD THE OVERLAY
// SEE http://php.net/manual/en/function.imagealphablending.php#77085
function imagelogo(&$dst_image, $src_image, $dst_w, $dst_h, $src_w, $src_h) {
ImageAlphaBlending($dst_image, TRUE);
ImageAlphaBlending($src_image, TRUE);
ImageCopy($dst_image, $src_image, 0, ($dst_h - $src_h), 0, 0, $src_w, $src_h);
}
// LOCATION OF THE IMAGES (COULD COME IN FROM $_GET URL STRING)
$original = 'http://www.someurl.com/avatar/f22b5cb6587140ba89fa96a616ac7d5b?s=100&r=r';
$overlay = 'http://www.someurl.com/codenameT/overlay.png';
// READ THE IMAGE AND THE OVERLAY FILE
// MAN PAGE http://php.net/manual/en/function.imagecreatefrompng.php
$im = ImageCreateFromPNG($original);
$wm = ImageCreateFromPNG($overlay);
// ADD OVERLAY USING LOCAL FUNCTION
imagelogo($im, $wm, imagesx($im), imagesy($im), imagesx($wm), imagesy($wm));
// SHOW THE IMAGE
header('Content-type: image/png');
ImagePNG($im);
O wrote this code to overlay 1 image over the other one... For some reason firefox reports that there is an error in the image and cannot be displayed.
Any clue?
// yeah.php
error_reporting(E_ALL);
// A FUNCTION TO ADD THE OVERLAY
// SEE http://php.net/manual/en/function.imagealphablending.php#77085
function imagelogo(&$dst_image, $src_image, $dst_w, $dst_h, $src_w, $src_h) {
ImageAlphaBlending($dst_image, TRUE);
ImageAlphaBlending($src_image, TRUE);
ImageCopy($dst_image, $src_image, 0, ($dst_h - $src_h), 0, 0, $src_w, $src_h);
}
// LOCATION OF THE IMAGES (COULD COME IN FROM $_GET URL STRING)
$original = 'http://www.someurl.com/avatar/f22b5cb6587140ba89fa96a616ac7d5b?s=100&r=r';
$overlay = 'http://www.someurl.com/codenameT/overlay.png';
// READ THE IMAGE AND THE OVERLAY FILE
// MAN PAGE http://php.net/manual/en/function.imagecreatefrompng.php
$im = ImageCreateFromPNG($original);
$wm = ImageCreateFromPNG($overlay);
// ADD OVERLAY USING LOCAL FUNCTION
imagelogo($im, $wm, imagesx($im), imagesy($im), imagesx($wm), imagesy($wm));
// SHOW THE IMAGE
header('Content-type: image/png');
ImagePNG($im);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
来自 newworld 的评论有所帮助,我发现我从中获取图像的 url 是 JPG 格式,并且需要 PNG 才能使我的代码中的功能正常工作。
Comment from neworld helped, i figure out that the url i was getting the image from was in JPG and it is required a PNG for the functions in my code to work.