img-exists

Check if remote image exists

Usage no npm install needed!

<script type="module">
  import imgExists from 'https://cdn.skypack.dev/img-exists';
</script>

README

Image Exists npm Package

Check if remote image exists

Features

  • Ping single remote image or an array of images
  • Does not consume time and traffic downloading the whole image
  • Cross browser (after Babel), pure vanilla js

API

ImageExists(input[, options], complete)

input

Type: String | Array
Single url, or an array of urls

options.timeout

Type: Number
Default: 1000 ms
Wait for a server response

complete

Type: Function
Callback function

Usage

let images = [
   'https://www.instagram.com/static/images/homepage/home-phones.png/43cc71bb1b43.png', 
   'https://assets.nationalgeographic.com/styleguide/stable/logos/ng-logo-2fl.svg', 
   'https://royalmail.com/sites/all/themes/royalmail2017/img/royalmail-logo.png',
   'https://avatars3.githubusercontent.com/u/18248992?s=40&v=4'
];

ImageExists(images, { timeout: 1000 }, (err, result) => {
   if(err){
      // ...
   }

   // ...
});