I am having the user upload an image of a logo and then try to position it on another image that I have on the server.
The position where the receipt will be superimposed as parameters by POST. The logo I receive is always a PNG, which may or may not have a transparent background and the same background must be maintained.
The problem: I do not know why I create black spaces, can you tell me what mistake I made?
Code :
session_start();
$posiX = $_POST['x'];
$posiY = $_POST['y'];
$datoImg = $_SESSION['genImg'];
$logo = $datoImg['logo']; //'logo.png'
$fondo = 'original.jpg';
foto($fondo, $logo, $posiX, $posiY);
function foto($img_original, $marcadeagua, $posiX, $posiY){
$trozosimagenorig=explode(".",$img_original);
$extensionimagenorig=$trozosimagenorig[count($trozosimagenorig)-1];
if (preg_match("/jpg|jpeg|JPG|JPEG/", $extensionimagenorig)) {
$imgm=imagecreatefromjpeg($img_original);
}
if (preg_match("/png|PNG/", $extensionimagenorig)) {
$imgm=imagecreatefrompng($img_original);
}
if (preg_match("/gif|GIF/", $extensionimagenorig)) {
$imgm=imagecreatefromgif($img_original);
}
$marcadeagua= imagecreatefrompng($marcadeagua);
$xmarcaagua = $posiX;
$ymarcaagua = $posiY;
$ximagen= imagesx($imgm);
$yimagen=imagesy($imgm);
imagecopy($imgm, $marcadeagua, $xmarcaagua, $ymarcaagua,
0, 0, $xmarcaagua, $ymarcaagua);
//se copia la imagen
imagejpeg($imgm,'../assets/originalrand.jpg');
}
Result obtained: Create those black spaces:
Original images:
Background image:
Logo image: