Last active
December 31, 2015 19:59
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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