Skip to content

Instantly share code, notes, and snippets.

@ZahidRasheed
Created December 16, 2016 09:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZahidRasheed/c68e26a979707ebbd5f77c8008c68da4 to your computer and use it in GitHub Desktop.
Save ZahidRasheed/c68e26a979707ebbd5f77c8008c68da4 to your computer and use it in GitHub Desktop.
<?php
//Set Variables:
$background = "bg.jpg"; //Background chose by user
$logo = "logo.png"; //This logo will always remain same
$userLogo = "20.png"; //Logo created by user.
$savePath = "/output/"; //Where to Save?
$showNotSave = true;
//No need to change anything below....
$bgImage = imagecreatefromjpeg($background);
//Apply Logo
$img = imagecreatefrompng($logo);
list($logoWidth, $logoHeight) = getimagesize($logo);
imagecopy($bgImage, $img, 30, 0, 0, 0, $logoWidth, $logoHeight);
imagedestroy($img);
//Apply Custom Logo
$img = imagecreatefrompng($userLogo);
$wx = imagesx($bgImage) / 2 - imagesx($img) / 2;
$wy = imagesy($bgImage) / 2 - imagesy($img) / 2;
imagecopy($bgImage, $img, $wx, $wy, 0, 0, imagesx($img), imagesy($img));
imagedestroy($img);
if ($showNotSave) {
header('Content-Type: image/png');
imagepng($bgImage);
} else {
imagepng($bgImage, $savePath);
}
imagedestroy($bgImage);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment