文字转图片
来源:互联网 发布:java violate关键字 编辑:程序博客网 时间:2024/06/04 18:51
安装
第一步下载libjpeg库
下载地址http://www.ijg.org/
下载jpegsrc.v9a.tar.gz这个文件
第二步
解压这个文件
第三步
打开终端,切换到解压的目录
执行
./configure --prefix=/usr/local/--enable-shared --enable-static
也可以根据需要添加其他库,如下:
--with-zlib[=DIR] Supportzlib (optionally in DIR)
--with-png[=DIR] Supportpng (optionally in DIR)
--with-freetype[=DIR] Supportfreetype (optionally in DIR)
--with-fontconfig[=DIR] Support fontconfig (optionally in DIR)
--with-jpeg[=DIR] Supportjpeg (optionally in DIR)
--with-liq[=DIR] Supportliq (optionally in DIR)
--with-xpm[=DIR] Supportxpm (optionally in DIR)
--with-tiff[=DIR] Supporttiff (optionally in DIR)
--with-webp[=DIR] Supportwebp (optionally in DIR)
第四步
执行
make
可能需要几分钟。
执行
make install
代码:
#include "gd.h"
#include <string.h>
int main(int argc, char **argv)
{
gdImagePtr im;
int black;
int white;
int brect[8];
int x, y;
char *err;
FILE *fpPng = NULL;
char *s = "中国人"; /* String to draw. */
double sz = 100.;
char *f = "/usr/share/fonts/wqy-microhei.ttc"; //根据需要下载
/* obtain brect so that we can size the image */
err = gdImageStringFT(NULL,&brect[0],0,f,sz,0.,0,0,s);
if (err) {
fprintf(stderr, "%s", err);
return 1;
}
/* create an image big enough for the string plus a little whitespace */
x= brect[2]-brect[6] + 6;
y= brect[3]-brect[7] + 6;
im = gdImageCreate(x,y);
/* Background color (first allocated) */
white = gdImageColorResolve(im, 255, 255, 255);
black = gdImageColorResolve(im, 0, 0, 0);
/* render the string, offset origin to center string*/
/* note that we use top-left coordinate for adjustment
*since gd origin is in top-left with y increasing downwards. */
x= 3 - brect[6];
y= 3 - brect[7];
err = gdImageStringFT(im,&brect[0],black,f,sz,0.0,x,y,s);
if (err) {
fprintf(stderr, "%s",err);
return 1;
}
fpPng = fopen("ft.png", "wb");
/* Write img to fpPng */
gdImagePng(im, fpPng);
fclose(fpPng);
/* Destroy it */
gdImageDestroy(im);
return 0;
}
问题:
1中文乱码。
中文要先改成UTF8格式。
- 【php】文字转图片
- 文字转图片
- 图片转base64文字
- Python之文字转图片
- 文字图片
- [转]C#动态生成文字图片
- 转:图片水印 文字水印 实例
- [转]C#动态生成文字图片
- 转:android- WebView 文字 、图片分开加载
- php 文字转图片-----长微博功能开发
- 【Servlet】Javaweb中文字转图片
- 在图片UIImage上绘制文字(字符串文字转图片)
- UIButton 同时显示图片文字 |-图片-文字-|
- 向图片写入文字!
- 水印图片、文字
- 文字环绕图片
- 指文字显图片
- 文字生成图片
- WebView的简单使用和常用方法、属性!
- 11 - Dockerfile之容器中运行MyEclipse搭建的JavaWeb项目(Docker系列)
- Ionic持久化存储(一)
- jquery 监测鼠标滚轮
- TortoiseGit通过SSH执行git clone报错SSH2_MSG_UNIMPLEMENTED
- 文字转图片
- Android Studio 中svn的使用
- AQS同步工具类对比
- asp去html
- 12 - Dockerfile指令集(Docker系列)
- 常用SQL汇总,Java开发工作高频数据库语句
- Postman-CI集成Jenkins
- 小博老师经验分享 ——参加编程大赛的小技巧
- 【卷积神经网络-进化史】从LeNet到AlexNet