imagegd

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

imagegdOutput GD image to browser or file

Descrição

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

Outputs a GD image to the given file.

Parâmetros

image

Um objeto GdImage, retornado por uma das funções de criação de imagem, como imagecreatetruecolor().

file

O caminho ou um recurso de stream aberto (que será fechado automaticamente após o retorno desta função) para salvar o arquivo. Se não for definido ou for null, o stream da imagem bruta será enviado diretamente.

Valor Retornado

Retorna true em caso de sucesso ou false em caso de falha.

Cuidado

Entretanto, se a biblioteca libgd falhar ao gerar a imagem, esta função retornará true.

Changelog

Versão Descrição
8.0.3 file is now nullable.
8.0.0 O parâmetro image agora espera uma instância de GdImage; anteriormente, um resource gd válido era esperado.
7.2.0 imagegd() now allows to output truecolor images. Formerly, these have been implicitly converted to palette.

Exemplos

Exemplo #1 Outputting a GD image

<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);

// Output the image
imagegd($im);

// Free up memory
imagedestroy($im);
?>

Exemplo #2 Saving a GD image

<?php
// Create a blank image and add some text
$im = imagecreatetruecolor(120, 20);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);

// Save the gd image
// The file format for GD images is .gd, see http://www.libgd.org/GdFileFormats
imagegd($im, 'simple.gd');

// Free up memory
imagedestroy($im);
?>

Notas

Nota:

The GD format is commonly used to allow fast loading of parts of images. Note that the GD format is only usable in GD-compatible applications.

Aviso

Os formatos de imagem GD e GD2 são formatos de imagem proprietários da biblioteca libgd. Eles devem ser considerados obsoletos e só devem ser usados para propósitos de desenvolvimento e testes.

Veja Também

  • imagegd2() - Output GD2 image to browser or file
add a note

User Contributed Notes

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