PHP | imagesavealpha() Function Last Updated : 19 Feb, 2020 Comments Improve Suggest changes Like Article Like Report The imagesavealpha() function is an inbuilt function in PHP which is used to set whether to retain full alpha channel information when saving PNG images or not. Alpha channel tells whether the image is fully transparent or opaque. Alpha blending has to be disabled using imagealphablending($im, false)) to retain the alpha-channel in the first place. Syntax: bool imagesavealpha( resource $image, bool $save_flag ) Parameters: This function accepts two parameters as mentioned above and described below: $image: It specifies the image resource to work on. $save_flag: It specifies whether to save the alpha channel or not. Return Value: This function returns TRUE on success or FALSE on failure. Below examples illustrate the imagesavealpha() function in PHP: Example 1: In this example we will enable saving alpha info. php <?php // Load the png image $png = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Turn off alpha blending imagealphablending($png, false); // Add alpha as 100 to image $transparent = imagecolorallocatealpha($png, 255, 255, 255, 100); imagefill($png, 0, 0, $transparent); // Set alpha flag to true so that // alpha info is saved in the image imagesavealpha($png, true); // Save the image imagepng($png, 'imagewithalphainfo.png'); imagedestroy($png); ?> Output: This will save the image in the same folder as imagewithalphainfo.png with alpha info. Example 2: In this example we will disable saving alpha info. php <?php // Load the png image $png = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-13.png'); // Turn off alpha blending imagealphablending($png, false); // Add alpha as 100 to image $transparent = imagecolorallocatealpha($png, 255, 255, 255, 100); imagefill($png, 0, 0, $transparent); // Set alpha flag to false so that // alpha info is not saved in the image imagesavealpha($png, false); // Save the image imagepng($png, 'imagewithoutalphainfo.png'); imagedestroy($png); ?> Output: This will save the image in the same folder as imagewithoutalphainfo.png without alpha info. Reference: https://www.php.net/manual/en/function.imagesavealpha.php Comment More infoAdvertise with us Next Article PHP | imagesavealpha() Function gurrrung Follow Improve Article Tags : Web Technologies PHP PHP-function PHP-image-functions Similar Reads PHP | imagewebp() Function The imagewebp() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to WebP and alter the quality of the image.Syntax:Â bool imagewebp( resource $image, int $to, int $q 2 min read PHP | imagechar() Function The imagechar() function is an inbuilt function in PHP which is used to draw a character horizontally. This function draws the first character of string in the image identified by image with its x and y-axis. The coordinate of the top-left corner is (0, 0). Syntax: bool imagechar( $image, $font, $x, 2 min read PHP | imageflip() Function The imageflip() function is an inbuilt function in PHP which is used to Flip an image horizontally, vertically or both horizontally and vertically using the given mode. Syntax: bool imageflip( $image, $mode ) Parameters: This function accepts two parameters as mentioned above and described below: $i 2 min read PHP | imagesettile() Function The imagesettile() function is an inbuilt function in PHP which is used to set the tile image for filling the area. Syntax: bool imagesettile( $image, $tile ) Parameters: This function accepts two parameters as mentioned above and described below: $image: It is returned by one of the image creation 2 min read PHP | imagesx() Function The imagesx() function is an inbuilt function in PHP which is used to return the width of the given image. Syntax: int imagesx( $image ) Parameters: This function accepts single parameters $image which is mandatory. This $image variable can store the image created by imagecreatetruecolor() image cre 1 min read PHP | imagecolorclosestalpha() Function The imagecolorclosestalpha() function is an inbuilt function in PHP which is used to get the index of closest color with alpha value in the given image. This function returns the index of the color in the palette of the image which is closest to the specified RGB value and alpha level. The alpha val 2 min read PHP | imagecolorexactalpha() Function The imagecolorexactalpha() function is an inbuilt function in PHP which is used to get the index of the specified color with alpha value. This function returns the index of the specified color and alpha value (RGBA value) in the palette of the image. Syntax: int imagecolorexactalpha ( $image, $red, 2 min read PHP | imagepng() Function The imagepng() function is an inbuilt function in PHP which is used to display image to browser or file. The main use of this function is to view an image in the browser, convert any other image type to PNG and applying filters to the image. Syntax: bool imagepng( resource $image, int $to, int $qual 2 min read PHP | imagealphablending() Function The imagealphablending() function is an inbuilt function in PHP which is used to set the blending mode for an image. This function allows to two different modes (blending mode and non-blending mode) to drawing truecolor images. Blending mode is not available when drawing used palette images. Syntax: 2 min read PHP | imagebmp() Function The imagebmp() function is an inbuilt function in PHP which is used to return the output or save a BMP version of the given image. Syntax: bool imagebmp( resource $image, mixed $to, bool $compressed ) Parameters: This function accept three parameters as mentioned above and described below: $image: I 1 min read Like