What is the function in PHP to copy one image onto another with a specified opacity?
To copy one image onto another with a specified opacity in PHP, you can use the imagecopymerge() function. This function takes the source and destination images, the coordinates where the source image should be placed on the destination image, and the opacity level. The opacity level ranges from 0 to 100, where 0 is completely transparent and 100 is completely opaque.
$source = imagecreatefrompng('source.png');
$destination = imagecreatefrompng('destination.png');
// Get the width and height of the source image
$source_width = imagesx($source);
$source_height = imagesy($source);
// Copy the source image onto the destination image with 50% opacity
imagecopymerge($destination, $source, 0, 0, 0, 0, $source_width, $source_height, 50);
// Output the final image
header('Content-Type: image/png');
imagepng($destination);
// Free up memory
imagedestroy($source);
imagedestroy($destination);
Keywords
Related Questions
- What are some common pitfalls when trying to decrease the gaps between table elements in PHP?
- How can PHP be utilized to interact with external applications, such as Microsoft Word, and handle file loading dynamically?
- How can the explode function in PHP be utilized to extract specific values from a string for comparison purposes?