PHPGD image on the other, send back

Asked

Viewed 60 times

2

I’m putting up a painting and inserting the background, but the image is on top. I wonder if you have any way to send backwards, like what graphic editors do, I’ve tried to invert the code, inserted first the background and then the frame, but the image only gets the size of the background.

Upshot inserir a descrição da imagem aqui

How it should look inserir a descrição da imagem aqui

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);
  • You have to invert even, otherwise it will be on top. the size of the image you choose in the imagesx() and imagesy(), whether it is the front or the bottom. And since you’re setting the bar, you have to reverse the origins too, or cut.

  • But I put the margins 0, still not right, gets cut

  • imagecopy($background, $image, 0, 0, 0, 0, 0, imagesx($image), imagesy($image) );

  • see how https://uploaddeimagens.com.br/images/000/800/original/download_%281%29.png? 1483017342

1 answer

2


Before overwriting the 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 one:

inserir a descrição da imagem aqui

Download: Main image. Download: Frame.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.