Skip to content

Instantly share code, notes, and snippets.

@viktorbezdek
Last active October 30, 2023 15:01
Show Gist options
  • Save viktorbezdek/b15773d437addfe9f34f052cf537fd8e to your computer and use it in GitHub Desktop.
Save viktorbezdek/b15773d437addfe9f34f052cf537fd8e to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "1766c385",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Required Libraries\n",
"import requests\n",
"from PIL import Image\n",
"from io import BytesIO\n",
"import IPython.display as display\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "7234d986",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# List of company names\n",
"companies = ['Google', 'Apple', 'Microsoft', 'Amazon', 'Facebook',\n",
" 'Tesla', 'Netflix', 'Adobe', 'Spotify', 'Samsung']\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d0e299fd",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Fetch and scale logos\n",
"scaled_logos = []\n",
"\n",
"for company in companies:\n",
" url = f\"https://api.brandfetch.io/v1/logo?domain={company.lower()}.com\"\n",
" response = requests.get(url)\n",
" \n",
" if response.status_code == 200:\n",
" img_data = response.json()['image']\n",
" img = Image.open(BytesIO(requests.get(img_data).content))\n",
" w, h = img.size\n",
" factor = (4000 / (w * h)) ** 0.5\n",
" img = img.resize((int(w * factor), int(h * factor)), Image.ANTIALIAS)\n",
" scaled_logos.append(img)\n",
" "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "65cd1fd2",
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Display scaled logos in Jupyter Notebook\n",
"for img in scaled_logos:\n",
" display.display(img)\n",
" "
]
}
],
"metadata": {},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment