Wern Ancheta

Adventures in Web Development.

How to Get the Logo of Any Company

| Comments

In one of my previous projects called StockSwitch, I had the need to fetch and utilize the logo of companies that are included in the NYSE, NASDAQ, and AMEX. In this article, I’ll be showing you how you can get the logo for any company so that you can use it in your projects.

The best way to get the logo of any company is via Clearbit’s logo API. All you have to do is replace the value of {DOMAIN-NAME} with the domain name used by the company that you want.

1
https://logo.clearbit.com/{DOMAIN-NAME}

For example, you want to utilize Google’s logo in your project. Simply create a new image tag and link to logo.clearbit.com followed by the domain name.

1
<img src="https://logo.clearbit.com/google.com">

You can also pass in the following optional parameters.

  • size – the size in pixels of the logo. The highest value I found to be valid is 800px. And the lowest is 5px.
  • format – you can pass either png or jpg.
  • greyscale – pass in a value of true if you want the logo to be in greyscale.

For example, you want the image to be in 50px and the format is png.

1
<img src="https://logo.clearbit.com/google.com?size=50&format=png">

You can also save it on your own server so you don’t use Clearbit’s resources every time the company logos are requested. Here’s a sample code on how you might do it in php.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<?php
$companies = array(
    'facebook.com',
    'google.com',
    'oracle.com',
    'amazon.com',
    'ebay.com',
    'uber.com',
    'twitter.com',
    'github.com'
);

foreach($companies as $company){

    $url = "https://logo.clearbit.com/{$company}?size=150&format=png";
    $contents = file_get_contents($url);
    file_put_contents('logos/' . $company . '.png' , $contents);

}
?>

The code above gets the contents returned from the clearbit logo URL and then saves it to the logos directory in the server.

Comments