GD PHP

Merging Two Ellipse Images

This PHP program demonstrates how to draw an ellipse on two images and merge them together into one image with the Graphics Draw, GD, library.

MergeEllipses.php

<?php
// Create two true color images to merge together
$qMainImage = imagecreatetruecolor(400, 100);
$qMergeimage = imagecreatetruecolor(200, 100);

// Turn on antialiasing for the merge image (it does not seem to work)
imageantialias($qMergeimage, true);

// Create colors for drawing the ellipses
$qCyan = imagecolorallocate($qMainImage, 0, 255, 255);
$qYellow = imagecolorallocate($qMergeimage, 255, 255, 0);

// Draw an ellipse on each image
// Format: (image, CenterX, CenterY, Width, Height, Color)
imageellipse($qMainImage, 100, 50, 190, 90, $qCyan);
imageellipse($qMergeimage, 100, 50, 190, 90, $qYellow);

// Merge the two images into one for display. The merge image is copied onto the main image.
// Format: (main image, copied image, DestX, DestY, SrcX, SrcY, SrcWidth, SrcHeight, SrcAlpha);
// The alpha value is in the range [0, 100], with 0 doing nothing and 100 as a full copy over.
imagecopymerge($qMainImage, $qMergeimage, 200, 0, 0, 0, 200, 100, 100);

// Output the resulting image and deallocate them both.
header('Content-type: image/png');
imagepng($qMainImage);
imagedestroy($qMainImage);
imagedestroy($qMergeimage);
?>
 

Output

 
 

© 2007–2024 XoaX.net LLC. All rights reserved.