好的PHP库,可将文本添加到图像(jpg,png等) [英] Good PHP Library To Add Text To Images (jpg, png, etc)
问题描述
我最近被一所学校雇用,该学校为年幼的孩子提供远程(在线)教育.他们希望一旦孩子完成了某些测试,作业等,就可以通过电子邮件生成和发送证书(jpg或png图像).显然,他们不会让所有的老师在Photoshop中重新创建每个证书.并更改每个孩子的名字,等等;那太浪费时间了,我怀疑他们的老师甚至不知道如何使用Photoshop.
I was recently hired by a school that provides distance (online) education to young children. They want to be able to generate and send certificates (jpg or png images) via email once a child has completed certain tests, assignments, etc. Obviously they won't get all of their teachers to re-create each certificate in Photoshop or something and change each childs name, etc; that would be way too time consuming and I doubt their teachers even know how to use Photoshop.
因此,我想知道在PHP中向图像添加文本的最佳方法是什么.该证书将类似于标准的学校证书,并且名称行将为空白.我希望文本去那里.
Therefore, I was wondering what the best way to add text to an image in PHP is. The certificate will be like a standard school certificate and the name line will be blank. I'd like the text to go there.
我在PHP中执行此操作的原因是因为这样,教师可以转到what.com/generate-certificate,然后在字段中键入孩子的姓名,然后将生成证书并将其发送给学生通过电子邮件即时发送.对老师来说很容易.
The reason I'm doing this in PHP is because that way the teachers can go to whatever.com/generate-certificate and then type in the child's name in a field and then the certificate will be generated and sent off to the student via email on the fly. Very easy for the teachers.
希望这个问题是有道理的.简而言之,我只想在PHP中使用库或其他简单方法在图像中添加一行文本(可能是jpeg).
Hopefully this question made sense. So in a nutshell I just want a library or some other simple way in PHP to add a line of text to an image (probably a jpeg).
非常感谢!
推荐答案
如果您不喜欢程序类型,则可以使用imagick
If you don't like procedural type, you can use imagick
<?php
/* Create some objects */
$image = new Imagick();
$draw = new ImagickDraw();
$pixel = new ImagickPixel( 'gray' );
/* New image */
$image->newImage(800, 75, $pixel);
/* Black text */
$draw->setFillColor('black');
/* Font properties */
$draw->setFont('Bookman-DemiItalic');
$draw->setFontSize( 30 );
/* Create text */
$image->annotateImage($draw, 10, 45, 0, 'The quick brown fox jumps over the lazy dog');
/* Give image a format */
$image->setImageFormat('png');
/* Output the image with headers */
header('Content-type: image/png');
echo $image;
来源: http://php.net/manual/zh-CN/imagick.annotateimage.php
这篇关于好的PHP库,可将文本添加到图像(jpg,png等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!