Skip to content

Instantly share code, notes, and snippets.

@vdite
Last active August 29, 2015 14:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vdite/30644e28301916789ff5 to your computer and use it in GitHub Desktop.
Save vdite/30644e28301916789ff5 to your computer and use it in GitHub Desktop.
This GDlib Trick let you stack different transparent png Images to one.
<?php
$image_arr=array('path1.png', 'path2.png', 'path3.png');
echo gd_gen_image($image_arr);
function gd_gen_image($arr){
$base = imagecreatetruecolor(913, 500);
$color = imagecolorallocatealpha($base, 0, 0, 0, 127);
imagefill($base, 0, 0, $color);
imagesavealpha($base, TRUE);
foreach($arr as $key=>$image_val){
$this_layer=imageCreateFromPNG($image_val);
ImageCopy ( $base, $this_layer, 0 , 0 , 0 , 0 , 913 , 500 );
}
// Begin capturing the byte stream
ob_start();
imagePNG($base);
$out=ob_get_clean();
// END capturing the byte stream
return "<img src='data:image/png;base64," . base64_encode( $out ) . "' />";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment