To download a game cover in .jpg format using the Steam API and a given AppID, you can use the Steam Storefront API, which is public and does not require an API key.
Here’s a Python function to do that:
✅ Function Overview:
- Input:
appid (Steam AppID of the game)
- Process:
- Calls the Steam Storefront API to get the game metadata.
- Extracts the header image URL (usually in JPEG format).
- Downloads and saves the image locally.
- Output: Saves
cover_<appid>.jpg in the current directory.
✅ Python Function:
import requests
import os
def download_steam_cover(appid, save_dir="."):
"""
Downloads the cover image for a Steam game using its AppID.
Args:
appid (int or str): The Steam AppID of the game.
save_dir (str): Directory to save the downloaded image.
Returns:
str: Path to the saved image file if successful, else None.
"""
url = f"https://store.steampowered.com/api/appdetails?appids={appid}"
try:
response = requests.get(url)
response.raise_for_status()
data = response.json()
# Check if data is available
if not data or not data[str(appid)]['success']:
print(f"[!] Failed to fetch data for AppID {appid}")
return None
header_image_url = data[str(appid)]['data'].get('header_image')
if not header_image_url:
print(f"[!] No header image found for AppID {appid}")
return None
# Download the image
image_response = requests.get(header_image_url)
image_response.raise_for_status()
# Construct save path
save_path = os.path.join(save_dir, f"cover_{appid}.jpg")
with open(save_path, 'wb') as f:
f.write(image_response.content)
print(f"[+] Cover image saved to: {save_path}")
return save_path
except requests.RequestException as e:
print(f"[!] HTTP error: {e}")
return None
except Exception as e:
print(f"[!] Unexpected error: {e}")
return None
✅ Example Usage:
if __name__ == "__main__":
appid = 570 # Dota 2
download_steam_cover(appid)
✅ Sample Output:
[+] Cover image saved to: ./cover_570.jpg
Let me know if you want it to resize the image or save it in a different format like PNG.