Skip to content

Instantly share code, notes, and snippets.

@rubdottocom
Last active December 31, 2015 19:59
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 rubdottocom/8036882 to your computer and use it in GitHub Desktop.
Save rubdottocom/8036882 to your computer and use it in GitHub Desktop.
PHP - Add transparent text watermark to an image to make it binary unique
<?php
// Create image resuource, use 'imagecreate*' that you need
$im = imagecreatefromstring($img_string);
imagesavealpha($im, true);
$trans_colour = imagecolorallocatealpha($im, 0, 0, 0, 127); // transparent background
imagefill($im, 0, 0, $trans_colour);
$text_color = imagecolorallocatealpha($im, 0, 0, 0, 126); // almost transparent text color "not visible human eye"
imagestring($im, 1, 0, 0, "UNIQUE_ID", $text_color);
ob_start ();
imagepng ($im);
$image_data = ob_get_contents ();
ob_end_clean ();
imagedestroy($im);
$img_string = $image_data;
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment