Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

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

Packages

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.

Behavior

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.

HTML

              
                <table class="tg">
  <tr>
    <th class="tg-fmq7">Image</th>
    <th class="tg-fmq7">img tag w/ alt text</th>
  </tr>
  <tr>
    <td class="tg-fmq7">
      <div id="upload1"><span id="upload" style="display:inline-block;">
      Select your own image:
      </span></div><span style="display:inline-block;">
<a href="#" id="upload_widget_opener"><img src="https://res.cloudinary.com/blog-demo/image/upload/v1534453250/upload_btn.png" style="margin:10px;margin-bottom:15px;vertical-align:bottom" alt="Upload Button" /></a>
</span></td>
    <td class="tg-fmq7" style="text-align:left">
      <div id="imgsrc1"><span id="imgsrc" style="display:inline-block;">
      </span></div>
      <div id="cloudsight1"><span id="cloudsight" style="display:inline-block;">
      </span></div>
    </td>
  </tr>
  <tr>
    <td class="tg-fmq7"><span style="display:inline-block;">
<img align="middle" width=200 height=200 src="https://res.cloudinary.com/blog-demo/image/upload/w_200,h_200,c_fill,dpr_2.0/dogs.jpg" style="margin-bottom:5px; display:block;" alt="Demo Image 1" />
</span></td>
    <td class="tg-fmq7" style="text-align:left">Alt Text generated by AWS Rekognition Add-on:<br>&lt;img src="https://res.cloudinary.com/blog-demo/image/upload/dogs.jpg" alt="animal, canine, dog"&gt;<br><br>Alt Text generated by CloudSight:<br>&lt;img src="https://res.cloudinary.com/blog-demo/image/upload/dogs.jpg"
      alt="three dogs sitting near wall"&gt;</td>
  </tr>
  <tr>
    <td class="tg-fmq7"><span style="display:inline-block;">
<img align="middle" width=200 height=200 src="https://res.cloudinary.com/blog-demo/image/upload/w_200,h_200,c_fill,dpr_2.0/president_obama.gif" style=" margin-bottom:5px; display:block;" alt="Demo Image 2" />
</span></td>
    <td class="tg-fmq7" style="text-align:left">Alt Text generated by AWS Rekognition Add-on:<br>&lt;img src="https://res.cloudinary.com/blog-demo/image/upload/president_obama.jpg" alt="Barack Obama, human, people, person"&gt;<br><br>Alt Text generated by CloudSight:<br>&lt;img src="https://res.cloudinary.com/blog-demo/image/upload/president_obama.jpg"
      alt="Barack Obama"&gt;</td>
  </tr>
  <tr>
    <td class="tg-fmq7"><span style="display:inline-block;">
<img align="middle" width=200 height=200 src="https://res.cloudinary.com/blog-demo/image/upload/w_200,h_200,c_fill,dpr_2.0/grand_canyon.jpg" style=" margin-bottom:5px; display:block;" alt="Demo Image 3" />
</span></td>
    <td class="tg-fmq7" style="text-align:left">Alt Text generated by AWS Rekognition Add-on:<br>&lt;img src="https://res.cloudinary.com/blog-demo/image/upload/grand_canyon.jpg" alt="canyon, mountain, nature"&gt;<br><br>Alt Text generated by CloudSight:<br>&lt;img src="https://res.cloudinary.com/blog-demo/image/upload/grand_canyon.jpg"
      alt="photo of Grand Canyon"&gt;</td>
  </tr>
  <tr>
    <td class="tg-fmq7"><span style="display:inline-block;">
<img align="middle" width=200 height=200 src="https://res.cloudinary.com/blog-demo/image/upload/w_200,h_200,c_fill,dpr_2.0/space_shuttle.jpg" style="margin-bottom:5px; display:block;" alt="Demo Image 4" />
</span></td>
    <td class="tg-fmq7" style="text-align:left">Alt Text generated by AWS Rekognition Add-on:<br>&lt;img src="https://res.cloudinary.com/blog-demo/image/upload/space_shuttle.jpg" alt="aircraft, space shuttle, spaceship"&gt;<br><br>Alt Text generated by CloudSight:<br>&lt;img src="https://res.cloudinary.com/blog-demo/image/upload/space_shuttle.jpg"
      alt="red and white space shuttle flying to space"&gt;</td>
  </tr>
</table>

<script src="//widget.cloudinary.com/global/all.js" type="text/javascript"></script>
<script src="https://cloudinary.com/javascripts/jquery.min.js">
</script>
              
            
!

CSS

              
                .tg  {border-collapse:collapse;border-spacing:0;}
.tg td{font-family:Arial, sans-serif;font-size:14px;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg th{font-family:Arial, sans-serif;font-size:14px;font-weight:normal;padding:10px 5px;border-style:solid;border-width:1px;overflow:hidden;word-break:normal;border-color:black;}
.tg .tg-fmq7{font-size:12px;font-family:"Lucida Console", Monaco, monospace !important;text-align:center}
              
            
!

JS

              
                var polling;

  function updateResult(result) {
    //Image tag generation part
    var url = result['secure_url'];
    url = url.replace(/v[\d]+/, 'w_200,h_200,c_fill,dpr_2.0');
    var imgurl = result['secure_url'];
    imgurl = imgurl.replace(/\/v[\d]+/, '');
    //Section 1: Alt text generation using Cloudsight API
    var cloudsightdata = "{ \"remote_image_url\": \"" + result['secure_url'] + "\", \"locale\": \"en_US\" }";
    const loadinggif = "https://res.cloudinary.com/blog-demo/image/upload/loading.gif";
    $.ajax({
      url: 'https://api.cloudsight.ai/v1/images',
      beforeSend: function() {
        document.getElementById("cloudsight").innerHTML = "<br>Alt Text generated by CloudSight:<br><img src=\"" + loadinggif + "\" alt=\"" + altText + "\">";
      },
      type: 'post',
      tryCount: 0,
      retryLimit: 3,
      data: cloudsightdata,
      headers: {
        authorization: 'CloudSight F0AV2R086Hd7dTmXyOPS0A',
        "cache-control": 'no-cache',
        "content-type": 'application/json'
      },
      dataType: 'json',
      success: function(data) {
        console.log(data);
        if (data.status == "not completed") {
          var pollurl = data.token;
          pollInterval(data);
        } else {
          setAltText(data);
        }
      },
    });

    function pollInterval(token) {
      var tokendata = token;
      polling = setInterval(function() { // run function every 2000 ms
        var pollurl = "https://api.cloudsight.ai/v1/images/" + tokendata.token;
        $.ajax({
          url: pollurl,
          type: 'get',
          headers: {
            authorization: 'CloudSight F0AV2R086Hd7dTmXyOPS0A',
            "cache-control": 'no-cache'
          },
          success: function(polldata) {
            console.log(polldata);
            if (polldata.status == "completed") {
              setAltText(polldata);
            }
          }
        });
      }, 2000);
    }

    function setAltText(altdata, pollhandler) {
      var cldimgsrctag = "<br>Alt Text generated by CloudSight:<br>&lt;img src=\"" + imgurl + "\" alt=\"" + altdata.name + "\"&gt;";
      console.log(altdata);
      document.getElementById("cloudsight").innerHTML = cldimgsrctag;
      if (polling) {
        clearInterval(polling);
      }
    }
    //Section 2: Alt text generation using AWS Rekognition API
    //Alt text generation part
    var altArray = result['tags'];
    var arrLen = altArray.length;
    var altText = "";
    for (var i = 0; i < arrLen; i++) {
      altText = altText + altArray[i];
      if (i < (arrLen - 1)) {
        altText = altText + ", ";
      }
    }
    var addonimgsrc = "<img src=\"" + url + "\" width=200 height=200 alt=\"" + altText + "\">";
    var addonimgsrctag = "<br>Alt Text generated by AWS Rekognition Add-on:<br>&lt;img src=\"" + imgurl + "\" alt=\"" + altText + "\"&gt;";
    document.getElementById("upload").innerHTML = addonimgsrc;
    document.getElementById("imgsrc").innerHTML = addonimgsrctag;
  };
  document.getElementById("upload_widget_opener").addEventListener("click", function() {
    cloudinary.openUploadWidget({
        cloud_name: 'blog-demo',
        upload_preset: 'ef4lenlr',
        sources: ['local', 'url', 'camera']
      },
      function(error, result) {
        updateResult(result[0]), console.log(result)
      });
  }, false);
              
            
!
999px

Console