Last active
August 29, 2015 14:01
-
-
Save vdite/30644e28301916789ff5 to your computer and use it in GitHub Desktop.
This GDlib Trick let you stack different transparent png Images to one.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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