php gd 图像质量
我正在尝试在特定图像上添加文本。它工作完美,但图像质量较低,尤其是 papyrus.ttf 字体。如何提高图像中文本的质量。但我需要高质量来打印输出。 这是我的代码..它非常简单。
header("Content-Type: image/jpeg");
$im = imagecreatefromjpeg("cosmos.jpg");
$black = ImageColorAllocate($im, 0, 0, 0);
Imagettftext($im, 14, 0, 10, 15, $black, 'papyrus.ttf', "Corey and Lisa ");
Imagettftext($im, 14, 0, 10, 35, $black, 'papyrus.ttf', " 1994, june");
Imagejpeg($im, '', 100);
ImageDestroy($im);
I 'm trying to add text on a specific image. Its working perfectly but the quality of image is low especially for papyrus.ttf font. How can i improve the quality of text in the image. But i need high quality to print the output.
Here is my code.. its very simple.
header("Content-Type: image/jpeg");
$im = imagecreatefromjpeg("cosmos.jpg");
$black = ImageColorAllocate($im, 0, 0, 0);
Imagettftext($im, 14, 0, 10, 15, $black, 'papyrus.ttf', "Corey and Lisa ");
Imagettftext($im, 14, 0, 10, 35, $black, 'papyrus.ttf', " 1994, june");
Imagejpeg($im, '', 100);
ImageDestroy($im);
Download: http://wneeds.com/gdtest.zip
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果 imageTTFText 质量失败,下一步要尝试的是 ImageFTText()。它使用 FreeType 库来渲染字体,这通常意味着质量显着提高。它需要安装并编译成 PHP 才能工作,这也是最常见的情况。尝试调用该函数,您将看到情况是否如此。
如果这不起作用,下一步是通过命令行使用 ImageMagick,或通过适当的 PHP 扩展。但先尝试一下 Freetype,它可能已经足够了。
If imageTTFText fails in Quality, the next step to try is ImageFTText(). It uses the FreeType library to render fonts, which usually means significantly better quality. It needs to be installed and compiled into PHP to work, which it most often is. Try calling the function and you'll see whether that is the case.
If that doesn't do, the next step is using ImageMagick either through the command line, or through the appropriate PHP extension. But try Freetype first, it could already be enough.