I need to put one image behind another image which is transparent. Another way of explaining this is changing the priority of what is shown first. Perhaps a layer? My code puts background (bg.png) on top/in front of the transparent image (sig.png):
header( 'Content-Type: image/png' );
$im = imagecreatefromstring( file_get_contents( 'public/sig.png' ) );
imagealphablending( $im, true );
imagesavealpha( $im, true );
$temp = imagecreatefromstring( file_get_contents( 'public/bg.png' ) );
imagecopy( $im, $temp, 34, 88, 0, 0, 850, 300 );
imagepng( $im );
imagedestroy( $im );
Switching the first two parameters in your call to imagecopy
will fix the draw order (you might need to update the other parameters too):
imagecopy($temp, $im, 34, 88, 0, 0, 850, 300);
imagepng($temp);
As stated in the manual , imagecopy
can be used to:
Copy a part of
src_im
ontodst_im
...
src_im
is the second parameter, dst_im
is the first parameter.
I created my custom image with transparent background as base and then merged two other images both background and main content together.
Thank you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.