List of gd/str2jpg.c

Sat Apr 20 14:11:22 2024

戻る

TEXTAREA で表示(カット&ペーストむき)

/*
	str2jpg

	指定された文字列を jpeg で出力する
	gd 内部のフォントを使用するので、ascii 文字列しか指定できない

コンパイル例
	gcc -o str2jpg str2jpg.c -L. -lgd -lpng -ljpeg -lz -lm

	2000/11/11 Ver.0.01
	2000/11/12 Ver.0.02
	2000/11/13 Ver.0.03

	Copyright (C) 2000	gama <gama@mvg.biglobe.ne.jp>
*/

#include "gd.h"
#include "gdfontl.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(int argc, char * argv[]) {
	gdImagePtr im;
	int black;		/* 背景色		*/
	int white;		/* 描画色		*/

	/* 文字列を環境変数から			*/
	char *s = argv[1];

	/* 幅は、文字数の幅 +2			*/
	int x=	strlen(s) * gdFontLarge->w	+2;
	/* 幅は、文字の高さ +2			*/
	int y=	gdFontLarge->h +2;
	/* アロケート					*/
	im = gdImageCreate(x, y);
	/* 背景色 (最初のアロケート)	*/
	black = gdImageColorAllocate(im, 0, 0, 0);		
	/* 描画色						*/
	white = gdImageColorAllocate(im, 255, 255, 255);		

	/* 真ん中に文字列を描く			*/
	gdImageString(im, gdFontLarge,
			im->sx / 2 - (strlen(s) * gdFontLarge->w / 2),
			im->sy / 2 - gdFontLarge->h / 2,
			s, white);
	/* イメージを strout へ出力		*/
	gdImageJpeg(im, stdout, -1);
	/* strout を吐き出す			*/
	fflush(stdout);
	/* イメージを破棄				*/
	gdImageDestroy(im);
}

戻る