Pregunta

¿Es posible crear imágenes con PHP (en lugar de simplemente enlazarlas a través de HTML) y, de ser así, dónde debería ir primero para aprender sobre tal cosa?

¿Fue útil?

Solución

Prefiero la biblioteca de GD : consulte los Ejemplos , y este ejemplo:

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

Salidas:

 imagecreatetrucolor example
(fuente: php.net )

Consulte imagecreatetruecolor .

Otros consejos

Sí, esto es posible. Creo que hay varias bibliotecas para lograr esto. El más utilizado es probablemente ImageMagick que en realidad no es específico de PHP pero viene con los enlaces adecuados.

Consulte también en la documentación de PHP .

Echa un vistazo a GD . Contiene una tonelada de funciones para la creación, manipulación e interrogación de imágenes. Tu instalación de PHP solo tiene que construirse con la biblioteca GD que probablemente fue.

Para tutoriales decentes sobre la generación de imágenes usando PHP:

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

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

PHP GD

Pear Image_Canvas (y Image_Graph para gráficos)

Esos son los dos que conozco.

MagickWand también es bastante bueno para eso, y bastante poderoso.

http://www.bitweaver.org/doc/magickwand/index.html

Este fragmento tomará una imagen, escribirá la 'rosa' en Vera, o cualquier fuente disponible, y enjuagará la imagen al navegador.

$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);
}

puede usar la biblioteca gd con diferentes funciones. y crea una buena imagen con el código

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

color a Negativo

if(!file_exists('dw-negative.png')) {
    $img = imagecreatefrompng('dw-manipulate-me.png');
    imagefilter($img,IMG_FILTER_NEGATE);
    imagepng($img,'db-negative.png');
    imagedestroy($img);
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top