PHP imagick注释setFont超过最大执行时间

发布于 2024-10-06 09:05:56 字数 1018 浏览 0 评论 0原文

我正在尝试使用 php imagick 将一些文本写入图像。 它在我的服务器上运行正常,但在我的 MacBook 上运行时遇到问题。

代码:

/* Text to write */
$text = "Hello World!";

/* Create Imagick objects */
$image = new Imagick();
$draw = new ImagickDraw();
$color = new ImagickPixel('#000000');
$background = new ImagickPixel('none'); // Transparent

/* Font properties */
$draw->setFont('Arial');
$draw->setFontSize(50);
$draw->setFillColor($color);
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);

/* Get font metrics */
$metrics = $image->queryFontMetrics($draw, $text);

/* Create text */
$draw->annotation(0, $metrics['ascender'], $text);

/* Create image */
$image->newImage($metrics['textWidth'], $metrics['textHeight'], $background);
$image->setImageFormat('png');
$image->drawImage($draw);

/* Save image */
header("Content-type: image/png");
echo $image;

当我在我的 MacBook 上运行此代码时,处理器卡在 100%,进程在 30 秒内被终止,并显示消息:第 13 行超出了最大执行时间 30 秒,其中是 $draw->setFont(); 的那个

谢谢您的回复...

Im tryin to write some text to an image using php imagick.
It runs okay on my server, but i have a problem running it on my macbook.

the code:

/* Text to write */
$text = "Hello World!";

/* Create Imagick objects */
$image = new Imagick();
$draw = new ImagickDraw();
$color = new ImagickPixel('#000000');
$background = new ImagickPixel('none'); // Transparent

/* Font properties */
$draw->setFont('Arial');
$draw->setFontSize(50);
$draw->setFillColor($color);
$draw->setStrokeAntialias(true);
$draw->setTextAntialias(true);

/* Get font metrics */
$metrics = $image->queryFontMetrics($draw, $text);

/* Create text */
$draw->annotation(0, $metrics['ascender'], $text);

/* Create image */
$image->newImage($metrics['textWidth'], $metrics['textHeight'], $background);
$image->setImageFormat('png');
$image->drawImage($draw);

/* Save image */
header("Content-type: image/png");
echo $image;

When i run this on my macbook, the processor gets stuck at at 100%, and the process is killed in 30 seconds with the message: Maximum execution time of 30 seconds exceeded in.....on line 13, which is the one with $draw->setFont();

Thank you for your responses...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

溺孤伤于心 2024-10-13 09:05:56

猜测: Arial 在您的系统上不可用,或者为 setFont() 提供了字体的完整路径

$draw->setFont('/path/to/ARIALB.ttf');

Guess: Arial is not available on your system or provide a complete path for the font to setFont()

$draw->setFont('/path/to/ARIALB.ttf');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文