/*---------------------------------------------------------------*/
|
/*
|
Titre : Un masque sur une image
|
|
URL : https://phpsources.net/code_s.php?id=671
|
Auteur : jonathan84
|
Date édition : 24 Oct 2012
|
*/
|
/*---------------------------------------------------------------*/
|
function addMaskToBackgroundImg($img, $mask, $dest = ''){
|
// Création du masque
|
$mask = imagecreatefrompng($mask);
|
// Dimensions du masque
|
$w = imagesx($mask);
|
$h = imagesy($mask);
|
|
// Création et rééchantillognage de l'image suivant les dimensions du masque
|
$imgTemp = imagecreatefromjpeg($img);
|
$imgOutput = imagecreatetruecolor($w, $h);
|
imagecopyresampled($imgOutput, $imgTemp, 0, 0, 0, 0, $w, $h, imagesx(
|
$imgTemp), imagesy($imgTemp));
|
imagedestroy($imgTemp);
|
// Activation du mode blending
|
imagealphablending($imgOutput, true);
|
// Fusion des images
|
$buffer = imagecopy($imgOutput, $mask, 0, 0, 0, 0, $w, $h);
|
// Affichage / écriture de l'image
|
if($dest == ''){
|
header('Content-Type: image/jpeg');
|
imagejpeg($imgOutput);
|
}
|
else imagejpeg($imgOutput, $dest);
|
// Destruction
|
imagedestroy($imgOutput);
|
imagedestroy($mask);
|
}
|
|
addMaskToBackgroundImg('background.jpg', 'mask.png', 'final.png');
|
| ?> |