D
D
dkrylov2017-06-04 17:55:35
PHP
dkrylov, 2017-06-04 17:55:35

How to overlay an image on a png image in php?

Hello!
I am writing a script that overlays several images on top of each other. There was a problem. When overlaying a png, for some reason it overlaps another png along with its transparency.

$png1 = imagecreatefrompng('1.png');
        imagealphablending($png1, false);
        imagesavealpha($png1, true);

       $png2 = imagecreatefrompng('2.png');
        imagealphablending($png2, false);
        imagesavealpha($png2, true);

       // Накладываем
        imagecopy($png1, $png2, 43, 95, 0, 0, imagesx($png2), imagesy($png2));

// отображаем изображение
        $result = imagepng($png1);
//И в $result картинку выводим с хедером

Googled, didn't google. An example from the documentation is overlay png on jpg. And I have 10 files layered on top of each other.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2017-06-05
@qonand

If I understand the problem correctly:

imagealphablending($png1, false)
imagealphablending($png2, false);

You turned off the color pairing mode ... and that's exactly what you need

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question