Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,130 changes: 645 additions & 485 deletions package-lock.json

Large diffs are not rendered by default.

34 changes: 11 additions & 23 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,21 @@
{
"name": "github-avatar-frame-api",
"version": "1.0.0",
"description": "An open-source API to frame GitHub avatars with themes for easy embedding.",
"main": "index.js",
"main": "dist/server.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"dev": "ts-node-dev --respawn --transpile-only src/server.ts",
"build": "tsc",
"start": "node dist/server.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/TechQuanta/github-avatar-frame-api.git"
},
"keywords": [],
"author": "",
"license": "ISC",
"type": "commonjs",
"bugs": {
"url": "https://github.com/TechQuanta/github-avatar-frame-api/issues"
},
"homepage": "https://github.com/TechQuanta/github-avatar-frame-api#readme",
"dependencies": {
"axios": "^1.11.0",
"express": "^5.1.0",
"sharp": "^0.34.3"
"axios": "^1.6.8",
"express": "^4.18.2",
"sharp": "^0.33.0"
},
"devDependencies": {
"@types/express": "^5.0.3",
"@types/node": "^24.3.1",
"nodemon": "^3.1.10",
"ts-node": "^10.9.2",
"typescript": "^5.9.2"
"@types/express": "^4.17.21",
"@types/node": "^20.11.30",
"ts-node-dev": "^2.0.0",
"typescript": "^5.4.3"
}
}
Binary file added public/frames/classic/frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions public/frames/classic/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Classic Theme",
"author": "ifthikaar",
"description": "Default classic frame",
"size": 256
}
Binary file added public/frames/neon/frame.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions public/frames/neon/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "Neon Theme",
"author": "ifthikaar",
"description": "Bright neon frame with glowing edges",
"size": 256
}
73 changes: 73 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import express, { Request, Response } from "express";
import axios from "axios";
import sharp from "sharp";
import path from "path";
import fs from "fs";

const app = express();
const PORT = 3000;

/**
* GET /api/framed-avatar/:username
* Example: /api/framed-avatar/octocat?theme=classic&size=256
*/
app.get("/api/framed-avatar/:username", async (req: Request, res: Response) => {
try {
const username = req.params.username;
const theme = (req.query.theme as string) || "classic";
const size = Number(req.query.size ?? 256);

// Fetch GitHub avatar
const avatarUrl = `https://github.com/${username}.png?size=${size}`;
const avatarResponse = await axios.get(avatarUrl, { responseType: "arraybuffer" });
const avatarBuffer = Buffer.from(avatarResponse.data);

// Locate theme frame
const themePath = path.join(__dirname, "..", "public", "frames", theme, "frame.png");
if (!fs.existsSync(themePath)) {
return res.status(404).json({ error: `Theme '${theme}' not found` });
}
const frameBuffer = fs.readFileSync(themePath);

// Resize and overlay
const avatarResized = await sharp(avatarBuffer).resize(size, size).png().toBuffer();
const frameResized = await sharp(frameBuffer).resize(size, size).png().toBuffer();

const finalImage = await sharp(avatarResized)
.composite([{ input: frameResized, gravity: "center" }])
.png()
.toBuffer();

res.set("Content-Type", "image/png");
res.send(finalImage);
} catch (error) {
console.error(error);
res.status(500).json({ error: "Something went wrong." });
}
});

/**
* GET /api/themes
* Lists all available themes + metadata
*/
app.get("/api/themes", (req: Request, res: Response) => {
const framesDir = path.join(__dirname, "..", "public", "frames");
const themes = fs.readdirSync(framesDir).filter(folder =>
fs.existsSync(path.join(framesDir, folder, "frame.png"))
);

const result = themes.map(theme => {
const metadataPath = path.join(framesDir, theme, "metadata.json");
let metadata = {};
if (fs.existsSync(metadataPath)) {
metadata = JSON.parse(fs.readFileSync(metadataPath, "utf-8"));
}
return { theme, ...metadata };
});

res.json(result);
});

app.listen(PORT, () => {
console.log(`🚀 Server running at http://localhost:${PORT}`);
});
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "ES2020",
"module": "commonjs",
"rootDir": "src",
"outDir": "dist",
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true
}
}