Frage
Ist es möglich, Bilder mit PHP zu erstellen (im Gegensatz zu einfach, um sie über HTML-Verknüpfung) und wenn ja, wo soll ich gehe zuerst über so etwas zu lernen?
Lösung
ziehe ich das GD-Bibliothek - check out die Beispiele , und dieses Beispiel:
<?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);
?>
Ausgänge:
(Quelle: php.net )
Andere Tipps
Ja, das ist möglich. Ich glaube, es gibt mehrere Bibliotheken, dies zu erreichen. Die am weitesten verbreitete ist wahrscheinlich ImageMagick das ist eigentlich nicht spezifisch PHP, sondern kommt mit entsprechenden Bindungen.
Sehen Sie auch in der PHP-Dokumentation .
Schauen Sie sich GD . Es enthält eine Tonne von Funktionen zur Bilderzeugung, Manipulation und Abfrage. Ihre PHP installieren Sie einfach mit der GD-Bibliothek gebaut hat, auf die es wahrscheinlich war.
Für anständig Tutorials auf Bildgenerierung mit PHP:
GD - http://devzone.zend.com/node/view/id / 1269
ImageMagick - http://www.sitepoint.com/article/dynamic-images -imagemagick
MagickWand ist ziemlich gut für das auch, und ziemlich mächtig.
http://www.bitweaver.org/doc/magickwand/index.html
Dieser Code-Schnipsel wird ein Bild nehmen, wrie in Vera die 'Rose', oder was auch immer Fonts zur Verfügung steht, und das Bild an den Browser spülen.
$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);
}
Sie können gd Bibliothek mit unterschiedlicher Funktion verwenden. und erstellen gutes Bild mit dem Code
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);
Farbe Negativ
if(!file_exists('dw-negative.png')) {
$img = imagecreatefrompng('dw-manipulate-me.png');
imagefilter($img,IMG_FILTER_NEGATE);
imagepng($img,'db-negative.png');
imagedestroy($img);
}