PHPGD image on the other, send back

2

I'm placing a frame and inserting the background, but the image is on top. I would like to know if there is any way to send back, like what graphic editors do, I already tried to invert the code, first inserted the background and then the frame, but the image is only the size of the background.

Result

HowshouldIstay?

Code

$imagem = imageCreateFromPng('imgs/quadro.png');

  imageAlphaBlending($imagem, true);
  imageSaveAlpha($imagem, true);


$fundo = imageCreateFromPng('imgs/bg.png');
  imageAlphaBlending($fundo, true);
  imageSaveAlpha($fundo, true);



imagecopy($imagem, $fundo, 60, 30, 0, 0, imagesx($fundo), imagesy($fundo) );


 header('Content-type: image/png');
  imagepng($imagem);
    
asked by anonymous 29.12.2016 / 00:16

1 answer

2

Before overlaying images, create a base. So:

 #Imagem base com fundo transparente
 $TempPngFile = imagecreatetruecolor(735, 620);
 $TransparentColor = imagecolorallocatealpha($TempPngFile, 0, 0, 0, 127);
 imagefill($TempPngFile, 0, 0, $TransparentColor);
 imagealphablending($TempPngFile, true);
 imagesavealpha($TempPngFile, true);
 #Abrindo imagem principal e fixando definições de transparência
 $img1 = imageCreateFromPng('assets/img/FrFUR0.png');
 imageAlphaBlending($img1, true);
 imageSaveAlpha($img1, true);
 #Abrindo moldura e forçando transparência
 $img2 = imageCreateFromPng('assets/img/FrFUR1.png');
 imageAlphaBlending($img2, true);
 imageSaveAlpha($img2, true);
 #Inserindo moldura e fixando posicionamento
 imagecopy($TempPngFile, $img1, 15, 15, 0, 0, imagesx($img1), imagesy($img1));
 imagecopy($TempPngFile, $img2, 0, 0, 0, 0, imagesx($img2), imagesy($img2));
 #Salva imagem no servidor
 # imagepng($TempPngFile, 'assets/uploads/NewPng.png');
 #ou mostra imagem no navegador
 header("Content-type: image/png");
 imagepng($TempPngFile);
 #Destrói imagens
 imageDestroy($TempPngFile);
 imageDestroy($img1);
 imageDestroy($img2);

The result is this here:

Download: Main Image . Download: Frame .

    
30.12.2016 / 20:01