HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<div id="screen-initial">
<h1 id="msg">Loading...</h1>
<progress id="load-progress" value="0" max="100"></progress>
</div>
<div id="screen-start" class="hidden">
<fieldset>
<label for="image-file-front-side">Front side image</label>
<input id="image-file-front-side" type="file" accept="image/*" capture="environment"/>
</fieldset>
<fieldset>
<label for="image-file-back-side">Back side image</label>
<input id="image-file-back-side" type="file" accept="image/*" capture="environment"/>
</fieldset>
<button id="start-button" type="button">Start</button>
</div>
<div id="screen-scanning" class="hidden">
<h1>Processing...</h1>
<img id="target-image" />
</div>
/**
* Copyright (c) Microblink Ltd. All rights reserved.
*/
*
{
box-sizing: border-box;
}
html,
body
{
width: 100%;
height: 100%;
}
html
{
margin: 0;
padding: 0;
font-size: 16px;
line-height: 24px;
font-family: sans-serif;
}
body
{
display: flex;
min-height: 100%;
margin: 0;
padding: 1.5rem;
justify-content: center;
align-items: center;
}
#screen-initial,
#screen-scanning
{
display: block;
width: 100%;
height: 100%;
}
/* Rules for better readability */
img
{
display: block;
width: 100%;
max-width: 320px;
height: auto;
}
video
{
width: 100%;
height: 100%;
}
textarea
{
display: block;
}
/* Camera feedback */
#screen-scanning
{
position: relative;
}
#camera-feedback
{
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 100%;
}
#camera-guides
{
position: absolute;
top: 0;
left: 0;
right: 0;
text-align: center;
font-weight: bold;
}
/* Auxiliary classes */
.hidden
{
display: none !important;
}
/**
* Copyright (c) Microblink Ltd. All rights reserved.
*/
/**
* This example app demonstrates how to use BlinkID ImageCapture In-browser SDK to achieve the following:
*
* - Change default SDK settings
* - Scan front and back side of the identity document with file upload (combined experience)
* - Send an image to web API for processing
*/
// General UI helpers
const initialMessageEl = document.getElementById( "msg" );
const progressEl = document.getElementById( "load-progress" );
const scanImageElement = document.getElementById( "target-image");
const inputImageFileFrontSide = document.getElementById( "image-file-front-side" );
const inputImageFileBackSide = document.getElementById( "image-file-back-side" );
/**
* Check browser support, customize settings and load WASM SDK.
*/
async function main()
{
// Check if browser has proper support for WebAssembly
if ( !BlinkIDImageCaptureSDK.isBrowserSupported() )
{
initialMessageEl.innerText = "This browser is not supported!";
return;
}
// 1. You can request a free trial license key, after you register, at Microblink Developer Hub
const licenseKey = "sRwAAAYHY2Rwbi5pb5ZgjD1QloirGkmBCZDF2DH6e8yVqo+rwfx7J3ZTi1MZfocQtbh4OdoJTgDJRNiK6ym8fSyNN0yVOVtL88LlRNCAdYGL6LD2e8EvO0n1i6ZQCHJkkwsy77SHEVFH7G2g/sUMEx5i3dHRj50n+CbmuPXgCIz6+jeCjo2zIcns6vrQ63h9GNF8qH9jPjDCq9hE5bFlEz3TRHEDbpxBoCsGCji1Ktt/7ns=";
// 2. Create instance of SDK load settings with your license key
const loadSettings = new BlinkIDImageCaptureSDK.WasmSDKLoadSettings( licenseKey );
// [OPTIONAL] Change default settings
// Show or hide hello message in browser console when WASM is successfully loaded
loadSettings.allowHelloMessage = true;
// In order to provide better UX, display progress bar while loading the SDK
loadSettings.loadProgressCallback = ( progress ) => ( progressEl.value = progress );
// Set absolute location of the engine, i.e. WASM and support JS files
loadSettings.engineLocation = "https://unpkg.com/@microblink/blinkid-imagecapture-in-browser-sdk@5.18.0/resources/";
// Set absolute location of the worker file
// IMPORTANT: function getWorkerLocation is a workaround for the CodePen since native Web Workers are not supported
loadSettings.workerLocation = await getWorkerLocation('https://unpkg.com/@microblink/blinkid-in-browser-sdk@5.18.0/resources/BlinkIDWasmSDK.worker.min.js');
// 3. Load SDK
BlinkIDImageCaptureSDK.loadWasmModule( loadSettings ).then
(
( sdk ) =>
{
document.getElementById( "screen-initial" )?.classList.add( "hidden" );
document.getElementById( "screen-start" )?.classList.remove( "hidden" );
document.getElementById( "start-button" )?.addEventListener( "click", ( ev ) =>
{
ev.preventDefault();
startScan( sdk );
});
},
( error ) =>
{
initialMessageEl.innerText = "Failed to load SDK!";
console.error( "Failed to load SDK!", error );
}
);
}
/**
* Scan single side of identity document with web camera.
*/
async function startScan( sdk, fileList )
{
processingOnWebApi = false;
document.getElementById( "screen-start" )?.classList.add( "hidden" );
document.getElementById( "screen-scanning" )?.classList.remove( "hidden" );
// 1. Create a recognizer objects which will be used to recognize single image or stream of images.
//
// BlinkID ImageCapture Recognizer - recognize a document and extract an image
const blinkIdImageCaptureRecognizer = await BlinkIDImageCaptureSDK.createBlinkIdImageCaptureRecognizer( sdk );
// 1.1. Enable scan of both sides for BlinkID ImageCapture recognizer
const settings = await blinkIdImageCaptureRecognizer.currentSettings();
settings[ "captureBothDocumentSides" ] = true;
await blinkIdImageCaptureRecognizer.updateSettings( settings );
// 2. Create a RecognizerRunner object which orchestrates the recognition with one or more
// recognizer objects.
const recognizerRunner = await BlinkIDImageCaptureSDK.createRecognizerRunner
(
// SDK instance to use
sdk,
// List of recognizer objects that will be associated with created RecognizerRunner object
[ blinkIdImageCaptureRecognizer ],
// [OPTIONAL] Should recognition pipeline stop as soon as first recognizer in chain finished recognition
false
);
// 3. Prepare front side image for scan action - keep in mind that SDK can only process images represented
// in internal CapturedFrame data structure. Therefore, auxiliary method "captureFrame" is provided.
// Make sure that image file is provided
const fileFrontSide = getImageFromInput( inputImageFileFrontSide.files );
if ( !fileFrontSide )
{
alert( "No image files provided!" );
// Release memory on WebAssembly heap used by the RecognizerRunner
recognizerRunner?.delete();
// Release memory on WebAssembly heap used by the recognizer
blinkIdImageCaptureRecognizer?.delete();
inputImageFileFrontSide.value = "";
return;
}
const imageFrame = await getImageFrame( fileFrontSide );
// 4. Start the recognition and await for the results
const processResultFrontSide = await recognizerRunner.processImage( imageFrame );
// 5. If recognition of the first side was successful, process the back side
if ( processResultFrontSide !== BlinkIDImageCaptureSDK.RecognizerResultState.Empty )
{
// 6. Prepare back side image for scan action
const fileBackSide = getImageFromInput( inputImageFileBackSide.files );
if ( !fileBackSide )
{
alert( "No image files provided!" );
// Release memory on WebAssembly heap used by the RecognizerRunner
recognizerRunner?.delete();
// Release memory on WebAssembly heap used by the recognizer
blinkIdImageCaptureRecognizer?.delete();
inputImageFileBackSide.value = "";
return;
}
const imageFrame = await getImageFrame( fileBackSide );
// 7. Start the recognition and await for the results
const processResultBackSide = await recognizerRunner.processImage( imageFrame );
if ( processResultBackSide !== BlinkIDImageCaptureSDK.RecognizerResultState.Empty )
{
// 8. If recognition of the back side was successful, obtain the result and display it
const results = await blinkIdImageCaptureRecognizer.getResult();
if ( results.state !== BlinkIDImageCaptureSDK.RecognizerResultState.Empty )
{
console.log( "BlinkIDImageCapture results", results );
if ( !results.frontSideCameraFrame || !results.backSideCameraFrame )
{
alert( "Could not extract images of a document. Please try again." );
}
else
{
processingOnWebApi = true;
console.log( "Sending request to web API..." );
getWebApiResults( results.frontSideCameraFrame, results.backSideCameraFrame );
}
}
}
else
{
alert( "Could not extract information from the back side of a document!" );
}
}
else
{
alert( "Could not extract information from the front side of a document!" );
}
// 9. Release all resources allocated on the WebAssembly heap and associated with camera stream
// Release memory on WebAssembly heap used by the RecognizerRunner
recognizerRunner?.delete();
// Release memory on WebAssembly heap used by the recognizer
blinkIdImageCaptureRecognizer?.delete();
// Hide scanning screen and show scan button again
inputImageFileFrontSide.value = "";
inputImageFileBackSide.value = "";
if ( !processingOnWebApi )
{
document.getElementById( "screen-start" )?.classList.remove( "hidden" );
document.getElementById( "screen-scanning" )?.classList.add( "hidden" );
}
}
function getImageFromInput( fileList ) {
let image = null;
const imageRegex = RegExp( /^image\// );
for ( let i = 0; i < fileList.length; ++i )
{
if ( imageRegex.exec( fileList[ i ].type ) )
{
image = fileList[ i ];
}
}
return image;
}
async function getImageFrame( file ) {
scanImageElement.src = URL.createObjectURL( file );
await scanImageElement.decode();
return BlinkIDImageCaptureSDK.captureFrame( scanImageElement );
}
/**
* Prepare and send image frames to web API for recognition processing.
*
* This function is using client library which is provided with the SDK.
*/
function getWebApiResults( frontSide, backSide )
{
// Create instance of client library - for more information see `client-library/README.md` file
const client = new Client.Client( Client.ApiType.SelfHosted, { apiLocation: "https://demoapi.microblink.com" } );
// Send image to web API for processing
const payload =
{
// Images from WASM library should be converted to Base64 from ImageData format.
"imageFrontSide": client.imageDataToBase64( frontSide ),
"imageBackSide": client.imageDataToBase64( backSide )
};
client.recognize( "/v1/recognizers/blinkid-combined", payload )
.then( ( results ) =>
{
const recognitionResults = results.response.data.result;
console.log( "API recognition results", recognitionResults );
if ( recognitionResults.recognitionStatus === "EMPTY" )
{
console.warn( "API processing returned empty results." );
alert( "API processing returned empty results." );
return;
}
alert
(
`Hello, ${ recognitionResults.firstName } ${ recognitionResults.lastName }!\n` +
`You were born on ${ recognitionResults.dateOfBirth.year }-${ recognitionResults.dateOfBirth.month }-${ recognitionResults.dateOfBirth.day }.`
);
} )
.catch( ( error ) =>
{
console.error( "API recognition error", error );
alert( "Could not process image on backend." );
} )
.finally( () =>
{
processingOnWebApi = false;
document.getElementById( "screen-start" )?.classList.remove( "hidden" );
document.getElementById( "screen-scanning" )?.classList.add( "hidden" );
} );
}
function getWorkerLocation(path) {
return new Promise((resolve) => {
window.fetch(path)
.then(response => response.text())
.then(data => {
const blob = new Blob( [ data ], { type: "application/javascript" } );
const url = URL.createObjectURL( blob );
resolve(url);
});
});
}
// Run
main();
Also see: Tab Triggers