Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

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.

+ add another resource


Add Packages

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.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <div class="pic-container">
  <img src=""
  <a class="credit" href="" target="_blank">Credit</a>

<div class="result-container">
  <div class="trigger">Loading...</div> 
  <canvas width="224px" height="224px" class="hide"></canvas>



                body {
  display: flex;
  justify-content: center;
  padding: 20px;
  font-family: Arial, Helvetica, sans-serif;

img {
  display: block;
  width: 224px;
  height: 224px;
  margin-right: 20px;
  border-radius: 8px;

.credit {
  margin-top: 6px;
  display: inline-block;
  font-size: 12px;
  color: #999;

canvas {
  border-radius: 8px;
  position: absolute;

.result-container {
  position: relative;
  width: 224px;
  height: 224px;

.trigger {
  border: 1px dashed #ccc;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  color: #e28843;

.trigger:hover {
  background-color: #eee;

.hide {
  display: none;


                async function start() {
  // Load the model.
  const tfliteModel = await tflite.loadTFLiteModel(

  // Setup the trigger button.

async function cartoonize(tfliteModel) {
  // Prepare the input tensors from the image.
  const inputTensor = tf.image
    // Resize.
    .resizeBilinear(tf.browser.fromPixels(document.querySelector("img")), [
    // Normalize.
  // Run the inference and get the output tensors.
  const outputTensor = tfliteModel.predict(inputTensor);
  // Process and draw the result on the canvas.
  // De-normalize.
  const data = outputTensor.add(1).mul(127.5);
  // Convert from RGB to RGBA, and create and return ImageData.
  const rgb = Array.from(data.dataSync());
  const rgba = [];
  for (let i = 0; i < rgb.length / 3; i++) {
    for (let c = 0; c < 3; c++) {
      rgba.push(rgb[i * 3 + c]);
  // Draw on canvas.
  const imageData = new ImageData(Uint8ClampedArray.from(rgba), 224, 224);
  const canvas = document.querySelector("canvas");
  const ctx = canvas.getContext("2d");
  ctx.putImageData(imageData, 0, 0);

function setupTrigger(tfliteModel) {
  const trigger = document.querySelector(".trigger");
  trigger.textContent = "Cartoonize!";
  document.querySelector(".trigger").addEventListener("click", (e) => {
    trigger.textContent = "Processing...";
    setTimeout(() => {