使用 PHP 和 GD 生成的图像被切断
这仅发生在实时服务器上。 在多个开发服务器上,映像正在按预期创建。
居住: 红帽
$ php --version
PHP 5.2.6 (cli) (built: May 16 2008 21:56:34)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
GD 支持 => 已启用 GD版=> 捆绑(2.0.34 兼容)
DEV: Ubuntu 8
$ php --version
PHP 5.2.4-2ubuntu5.3 with Suhosin-Patch 0.9.6.2 (cli) (built: Jul 23 2008 06:44:49)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
GD 支持 => 已启用 GD版=> 2.0 或更高版本
<?php
$image = imagecreatetruecolor($width, $height);
// Colors in RGB
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $width, $height, $white);
imagettftext($image, $fontSize, 0, 0, 50, $black, $font, $text);
imagegif($image, $file_path);
?>
在完美的世界中,我希望实时服务器和开发服务器运行相同的发行版,但实时服务器必须是 Red Hat。
我的问题是,有谁知道使用 GD 的捆绑版本会导致图像最右侧部分被截断的具体差异吗?
编辑:我没有内存不足。 日志文件中没有生成任何错误。 就 php 而言,图像正在正确生成。 这就是为什么我认为这是捆绑版本的 GD 特定问题。
This is only happening on the live server. On multiply development servers the image is being created as expected.
LIVE:
Red Hat
$ php --version
PHP 5.2.6 (cli) (built: May 16 2008 21:56:34)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
GD Support => enabled
GD Version => bundled (2.0.34 compatible)
DEV:
Ubuntu 8
$ php --version
PHP 5.2.4-2ubuntu5.3 with Suhosin-Patch 0.9.6.2 (cli) (built: Jul 23 2008 06:44:49)
Copyright (c) 1997-2007 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies
GD Support => enabled
GD Version => 2.0 or higher
<?php
$image = imagecreatetruecolor($width, $height);
// Colors in RGB
$white = imagecolorallocate($image, 255, 255, 255);
$black = imagecolorallocate($image, 0, 0, 0);
imagefilledrectangle($image, 0, 0, $width, $height, $white);
imagettftext($image, $fontSize, 0, 0, 50, $black, $font, $text);
imagegif($image, $file_path);
?>
In a perfect world I would like the live server and the dev server to be running the same distro, but the live server must be Red Hat.
My question is does anyone know the specific differences that would cause the right most part of an image to be cut off using the bundled version of GD?
EDIT: I am not running out of memory. There are no errors being generated in the logs files. As far as php is concerned the image is being generated correctly. That is why I believe it to be a GD specific problem with the bundled version.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
也许您内存不足或类似的情况? 您是否仔细检查了所有日志文件等?
Maybe you are running out of memory or something similar? Did you double check all logfiles, etc.?
它是否 100% 一致并且始终位于同一位置? 如果不是,则可能是资源问题——执行脚本的时间或内存限制。 尝试调整 php.ini 设置,重新启动 Web 服务器,进行测试。
Is it 100% consistent and always at the same place? If not, it might be a resource issue -- time to execute the script or memory limitation. Try tweaking the php.ini settings, rebooting web server, testing.
这取决于图像吗?
最近我在 PHP 和 PHP 中发现了一个奇怪的错误/功能。 GD。
当尝试调整大小和编辑具有全白色背景(约 3MB)的 JPEG 时,它会失败。 它确实可以处理其他更大的图像(约 4MB)和更复杂的背景。
我发现当 GD 打开图像进行编辑时,白色背景图像比更复杂的图像以更大的比例增长。 某些图像的这种比例导致 PHP/GD 失败并中途剪切图像。
威廉
Does it depend on the image ?
Recently I discovered a strange bug/feature in PHP & GD.
When trying to resize and edit JPEGs that had an all white background (c. 3MB), it would fail. It DID work with other images that were larger (c. 4MB), and more complicated backgrounds.
I worked out that when GD opened the images to edit, the white back ground images grew by a greater ratio than the more complex images. This ratio for some images caused PHP/GD to fail and cut of images halfway.
William
你有没有输出$width的值来看看是否正确?
Have you had the value of $width output to see whether it is correct?
可能不是图像被切断。 可能是文字被截断了。
TTF 字体有开销和填充。 尝试更大的画布,看看是否得到相同的结果。
It might not be the image is being cut off. It might be the text being cut off.
TTF font has overhead and paddings. Try a larger canvas see if the you get the same result.