Skip to content

Instantly share code, notes, and snippets.

@zburgermeiszter
Last active August 29, 2015 14:04
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 zburgermeiszter/9b2366c26aa296acc7c2 to your computer and use it in GitHub Desktop.
Save zburgermeiszter/9b2366c26aa296acc7c2 to your computer and use it in GitHub Desktop.
Notes
<?php
// The header line informs the server of what to send the output
// as. In this case, the server will see the output as a .png
// image and send it as such
header ("Content-type: image/png");
// Defining the background image. Optionally, a .jpg image could
// could be used using imagecreatefromjpeg, but I personally
// prefer working with png
$background = imagecreatefrompng("background.png");
///*
// Defining the overlay image to be added or combined.
$insert = imagecreatefrompng("overlay.png");
// Select the first pixel of the overlay image (at 0,0) and use
// it's color to define the transparent color
//imagecolortransparent($insert,imagecolorat($insert,0,0));
// Get overlay image width and height for later use
$insert_w = imagesx($insert);
$insert_h = imagesy($insert);
// Combine the images into a single output image. Some people
// prefer to use the imagecopy() function, but more often than
// not, it sometimes does not work. (could be a bug)
imagecopymerge($background,$insert,100,200,0,0,$insert_w,$insert_h,100);
// Output the results as a png image, to be sent to viewer's
// browser. The results can be displayed within an HTML document
// as an image tag or background image for the document, tables,
// or anywhere an image URL may be acceptable.*/
imagepng($background,"",9);
// See more at: http://www.codewalkers.com/c/a/Miscellaneous/Overlapping-Images-with-GD/1/#sthash.Fn7fiHlY.dpuf
// Read more at http://www.codewalkers.com/c/a/Miscellaneous/Overlapping-Images-with-GD/1/#0XHaTwA6plMKVu53.99
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment