PHP で画像を作成することは可能ですか (単純に HTML 経由で画像にリンクするのではなく)。
7 に答える
私はGD ライブラリを好みます - Examplesとこの例をチェックしてください:
<?php
header ("Content-type: image/png");
$im = @imagecreatetruecolor(120, 20)
or die("Cannot Initialize new GD image stream");
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
?>
出力:
(出典: php.net )
imagecreatetruecolorを参照してください。
はい、これは可能です。これを達成するためのライブラリは複数あると思います。最も広く使用されているのはおそらくImageMagickです。これは実際には PHP 固有ではありませんが、適切なバインディングが付属しています。
PHP ドキュメントも参照してください。
GDをチェックしてください。画像の作成、操作、尋問のための機能がたくさん含まれています。あなたのPHPインストールは、おそらくそうであったGDライブラリで構築する必要があります。
PHP を使用した画像生成に関するまともなチュートリアル:
GD - http://devzone.zend.com/node/view/id/1269
ImageMagick - http://www.sitepoint.com/article/dynamic-images-imagemagick
gd ライブラリをさまざまな機能で使用できます。コードで良いイメージを作成します
header("Content-Type: image/png");
//try to create an image
$im = @imagecreate(800, 600)
or die("Cannot Initialize new GD image stream");
//set the background color of the image
$background_color = imagecolorallocate($im, 0xFF, 0xCC, 0xDD);
//set the color for the text
$text_color = imagecolorallocate($im, 133, 14, 91);
//adf the string to the image
imagestring($im, 5, 300, 300, "I'm a pretty picture:))", $text_color);
//outputs the image as png
imagepng($im);
//frees any memory associated with the image
imagedestroy($im);
色をネガに
if(!file_exists('dw-negative.png')) {
$img = imagecreatefrompng('dw-manipulate-me.png');
imagefilter($img,IMG_FILTER_NEGATE);
imagepng($img,'db-negative.png');
imagedestroy($img);
}
MagickWand はその点でも非常に優れており、非常に強力です。
http://www.bitweaver.org/doc/magickwand/index.html
このスニペットは、画像を取得し、Vera または利用可能なフォントで「バラ」を書き込み、その画像をブラウザーにフラッシュします。
$drawing_wand=NewDrawingWand();
DrawSetFont($drawing_wand,"/usr/share/fonts/bitstream-vera/Vera.ttf");
DrawSetFontSize($drawing_wand,20);
DrawSetGravity($drawing_wand,MW_CenterGravity);
$pixel_wand=NewPixelWand();
PixelSetColor($pixel_wand,"white");
DrawSetFillColor($drawing_wand,$pixel_wand);
if (MagickAnnotateImage($magick_wand,$drawing_wand,0,0,0,"Rose") != 0) {
header("Content-type: image/jpeg");
MagickEchoImageBlob( $magick_wand );
} else {
echo MagickGetExceptionString($magick_wand);
}