将透明文本写入 jpeg
到处都在谈论在透明图像上添加文本。我想将水印之类的文本(即透明文本)添加到 jpeg 格式的经典图像中。我尝试了一切,我发现了什么。有人解决吗?完全可以解决吗?
我想使用GD(不是imagick),因为项目是基于GD构建的。
谢谢
编辑: 这就是我使用的
$textBox = imagettfbbox($fontSize, $angle, $font, $text);
//file is orig image
$im = imagecreatefromjpeg($file);
$transparent = imagecolorallocate($im, 250, 250, 250);
//does not help - text disapper
//$transparent = imagecolorallocatealpha($im, 0, 0, 0, 127);
//does not help, burn whole to image
//imagealphablending($im, false);
//imagesavealpha($im, true);
//calculate position - $imageInfo is getsizeimage on orig image
$textX = ($imageInfo[0] / 2) - ($textBox[2] / 2);
$textY = ($imageInfo[1] / 2) - ($textBox[5] / 2);
//does not help
//imagecolortransparent ($im, $transparent);
imagettftext($im, $fontSize, $angle, $textX, $textY, $transparent, $font, $text);
header("Content-Type: image/jpeg");
imagejpeg($im);
简单的解决方案
Color is neccessary set by imagecolorresolvealpha($im, 0, 0, 0, 100);
Everywhere is talking about adding text on transparent image. I would like add text like watermark (so mean transparent text) to classic image in jpeg format. I tried everything, what I found. Has someone solution for it? Is solutionable at all?
I would like to use GD (not imagick), because project is built on GD.
Thanks
Edit:
This is what I using
$textBox = imagettfbbox($fontSize, $angle, $font, $text);
//file is orig image
$im = imagecreatefromjpeg($file);
$transparent = imagecolorallocate($im, 250, 250, 250);
//does not help - text disapper
//$transparent = imagecolorallocatealpha($im, 0, 0, 0, 127);
//does not help, burn whole to image
//imagealphablending($im, false);
//imagesavealpha($im, true);
//calculate position - $imageInfo is getsizeimage on orig image
$textX = ($imageInfo[0] / 2) - ($textBox[2] / 2);
$textY = ($imageInfo[1] / 2) - ($textBox[5] / 2);
//does not help
//imagecolortransparent ($im, $transparent);
imagettftext($im, $fontSize, $angle, $textX, $textY, $transparent, $font, $text);
header("Content-Type: image/jpeg");
imagejpeg($im);
Simple solution
Color is neccessary set by imagecolorresolvealpha($im, 0, 0, 0, 100);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个,它对我有用......
添加文本作为水印的 Php 脚本
这里是我获取它的参考
添加图像作为水印的Php脚本
Try this it works for me...
Php Script to add Text as a watermark
Here is the reference from where I got it
Php Script to add Image as a watermark