2008-08-24 17 views
6

¿Es posible crear imágenes con PHP (en lugar de simplemente vincularlas a través de HTML) y, de ser así, dónde debo ir primero para obtener más información sobre tal cosa?Imágenes en PHP

Respuesta

12

Yo prefiero el GD library - echa un vistazo a the Examples, 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 http://uk2.php.net/manual/en/figures/image.imagecreatetruecolor.png

Ver imagecreatetruecolor.

+0

Siempre se debe tratar de usar la función header() en el último momento posible (como por ejemplo, antes de la imagepng) Funciton () Como está ahora, si el script php muere "No se puede inicializar la nueva secuencia de imágenes GD", el navegador intentará interpretarlo como un archivo .gif, por lo que no será inteligible. – stalepretzel

6

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

Ver también en el PHP documentation.

3

Consulte GD. Contiene un montón de funciones para la creación, manipulación e interrogación de imágenes. Su instalación de PHP solo tiene que construirse con la biblioteca de GD que probablemente era.

0

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

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

Este fragmento se llevará una imagen, la WRIE 'Rose' en Vera, o lo que las fuentes están disponibles, y al ras de la imagen para el 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); 
} 
0

puede usar la biblioteca gd con una función diferente de la misma. y crear 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); 
} 
Cuestiones relacionadas