PHP 8.5.0 Alpha 2 available for testing

imagegd

(PHP 4 >= 4.0.7, PHP 5, PHP 7, PHP 8)

imagegdGenera una imagen en formato GD, hacia el navegador o un fichero

Descripción

imagegd(GdImage $image, ?string $file = null): bool

Genera o guarda el fichero file en formato GD.

Parámetros

image

Un objeto GdImage, retornado por una de las funciones de creación de imágenes, como imagecreatetruecolor().

file

The path or an open stream resource (which is automatically closed after this function returns) to save the file to. If not set or null, the raw image stream will be output directly.

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Precaución

However, if libgd fails to output the image, this function returns true.

Historial de cambios

Versión Descripción
8.0.3 file ahora es nullable.
8.0.0 image expects a GdImage instance now; previously, a valid gd resource was expected.
7.2.0 imagegd() ahora permite producir imágenes TrueColor. Anteriormente, eran convertidas implícitamente a paleta.

Ejemplos

Ejemplo #1 Mostrar una imagen GD

<?php
// Creación de una imagen vacía y adición de texto
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "Un texto simple", $text_color);

// Mostrar la imagen
imagegd($im);

?>

Ejemplo #2 Guardar una imagen GD

<?php
// Creación de una imagen vacía y adición de texto
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "Un texto simple", $text_color);

// Guardar la imagen GD
// El formato de fichero para imágenes GD es .gd, ver http://www.libgd.org/GdFileFormats
imagegd($im, 'simple.gd');

?>

Notas

Nota:

El formato GD se utiliza comúnmente para permitir la carga rápida de partes de una imagen. Tenga en cuenta que el formato GD solo es utilizable en aplicaciones compatibles con GD.

Advertencia

The GD and GD2 image formats are proprietary image formats of libgd. They have to be regarded obsolete, and should only be used for development and testing purposes.

Ver también

  • imagegd2() - Genera una imagen en formato GD2, hacia el navegador o un fichero
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top