简体   繁体   中英

How can I add a background image under a base64 generated image using PHP?

This works:

$img = imagecreatefromstring(base64_decode(str_replace('data:image/png;base64,', '', $image)));

$width = imagesx($img);
$height = imagesy($img);
$output = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($output,  255, 255, 255);
imagefilledrectangle($output, 0, 0, $width, $height, $white);
imagecopy($output, $img, 0, 0, 0, 0, $width, $height);
imagejpeg($output, './'.$filename);
echo $filename;

But I want to add a background image under this image, what I searched maybe using imagecreatefromjpeg("bg.png") but how can I achieve?

  • bg image
  • new image
  • merge them together

Here is a example how to use it:

http://php.net/manual/en/image.examples.merged-watermark.php

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM