<?php //Require the Bar Code authenticator. Circumvents the autoloader in this instance. require_once '../BarCodeAuthenticator.class.php'; // Value to hash to MD5, and then encode into a Bar Code Image (that will then be output to the browser) $toHash = "This Is A String To Encode"; // Create the Bar Code Authenticator Object $bca = new \RLerner\BarCodeAuthenticator\BarCodeAuthenticator(); // 16 is the size you want to use for a 32 character string ((16*16)/8) = 32 $bca->imageSize = 16; // Convert this string to MD5, and then convert it to a binary stream. $binaryStream = $bca->stringToBinaryStream(md5($toHash)); // Now Convert the Binary Stream to a Bar Coded Image $imageResource = $bca->streamToImage($binaryStream); // Set the MIME Type to inform the browser that the document is an image, of type PNG header("Content-Type: image/png"); // Output the PNG Image imagepng($imageResource);
<?php //Require the Bar Code authenticator. Circumvents the autoloader in this instance. require_once '../BarCodeAuthenticator.class.php'; // Create the Bar Code Authenticator Object $bca = new \RLerner\BarCodeAuthenticator\BarCodeAuthenticator(); // Use GD Library to create an image resource for the image containing the bar code. $im = imagecreatefrompng("demo.png"); // Since the demo.png image is 100x100, and the bar code is in the bottom right, we need to // set the base reading offset to 84 for each coordinate. $bca->baseReadingOriginX = $bca->baseReadingOriginY = 84; // Convert the image to a binary stream of 100110010101 etc $stream = $bca->imageToStream($im); // Convert the binary stream back to ASCII characters, and output. echo $bca->binaryStreamToString($stream);