imagecolortransparent

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecolortransparentDefine a color as transparent

Description

imagecolortransparent(GdImage $image, ?int $color = null): int

Gets or sets the transparent color in the given image.

Parameters

image

A GdImage object, returned by one of the image creation functions, such as imagecreatetruecolor().

color

A color identifier created with imagecolorallocate().

Return Values

The identifier of the new (or current, if none is specified) transparent color is returned. If color is null, and the image has no transparent color, the returned identifier will be -1.

Changelog

Version Description
8.0.0 image expects a GdImage instance now; previously, a resource was expected.
8.0.0 color is now nullable.

Examples

Example #1 imagecolortransparent() example

<?php
// Create a 55x30 image
$im imagecreatetruecolor(5530);
$red imagecolorallocate($im25500);
$black imagecolorallocate($im000);

// Make the background transparent
imagecolortransparent($im$black);

// Draw a red rectangle
imagefilledrectangle($im445025$red);

// Save the image
imagepng($im'./imagecolortransparent.png');
imagedestroy($im);
?>

The above example will output something similar to:

Output of example : imagecolortransparent()

Notes

Note:

Transparency is copied only with imagecopymerge() and true color images, not with imagecopy() or pallete images.

Note:

The transparent color is a property of the image, transparency is not a property of the color. Once you have set a color to be the transparent color, any regions of the image in that color that were drawn previously will be transparent.

Here you can write a comment


Please enter at least 10 characters.
Loading... Please wait.
* Pflichtangabe
There are no comments available yet.

PHP cURL Tutorial: Using cURL to Make HTTP Requests

cURL is a powerful PHP extension that allows you to communicate with different servers using various protocols, including HTTP, HTTPS, FTP, and more. ...

TheMax

Autor : TheMax
Category: PHP-Tutorials

Midjourney Tutorial - Instructions for beginners

There is an informative video about Midjourney, the tool for creating digital images using artificial intelligence, entitled "Midjourney tutorial in German - instructions for beginners" ...

Mike94

Autor : Mike94
Category: KI Tutorials

Basics of views in MySQL

Views in a MySQL database offer the option of creating a virtual table based on the result of an SQL query. This virtual table can be queried like a normal table without changing the underlying data. ...

admin

Autor : admin
Category: mySQL-Tutorials

Publish a tutorial

Share your knowledge with other developers worldwide

Share your knowledge with other developers worldwide

You are a professional in your field and want to share your knowledge, then sign up now and share it with our PHP community

learn more

Publish a tutorial