6

是否可以使用 PHP 创建图像(而不是简单地通过 HTML 链接到它们),如果可以,我应该先去哪里了解这样的事情?

4

7 回答 7

12

我更喜欢GD 库- 查看示例和这个示例:

<?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);
?>

输出:

imagecreatetrucolor 示例
(来源:php.net

请参阅imagecreatetruecolor

于 2008-08-24T16:11:39.580 回答
6

是的,这是可能的。我相信有多个图书馆可以做到这一点。最广泛使用的可能是ImageMagick,它实际上不是 PHP 特定的,但带有适当的绑定。

另请参阅PHP 文档

于 2008-08-24T16:04:32.437 回答
3

看看GD。它包含大量用于图像创建、操作和查询的功能。您的 PHP 安装只需要使用它可能是的 GD 库构建。

于 2008-08-24T16:06:31.653 回答
3

有关使用 PHP 生成图像的体面教程:

GD - http://devzone.zend.com/node/view/id/1269

ImageMagick - http://www.sitepoint.com/article/dynamic-images-imagemagick

于 2008-08-24T16:33:40.997 回答
1

PHP GD

Pear Image_Canvas(以及用于图形的Image_Graph

这是我认识的两个。

于 2008-08-24T16:11:21.097 回答
0

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);
}
于 2009-05-16T00:28:08.923 回答
0

您可以使用具有不同功能的 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);
}
于 2015-10-01T11:40:25.080 回答