AeThex-Connect/astro-site/src/utils/unsplash.js

106 lines
3.5 KiB
JavaScript

/**
* Unsplash Image Utility
* Provides free stock images for AeThex Connect
* Uses Unsplash Source API (no key required for basic usage)
*/
// Curated gaming/tech collection IDs from Unsplash
const COLLECTIONS = {
gaming: '1424240', // Gaming collection
tech: '3582603', // Technology collection
neon: '1459961', // Neon/cyberpunk aesthetic
dark: '827743', // Dark moody shots
abstract: '1065976', // Abstract patterns
};
/**
* Get a random image URL from Unsplash
* @param {Object} options
* @param {number} options.width - Image width
* @param {number} options.height - Image height
* @param {string} options.query - Search query
* @param {string} options.collection - Collection ID
* @returns {string} Image URL
*/
export function getUnsplashImage({ width = 1920, height = 1080, query, collection } = {}) {
const base = 'https://source.unsplash.com';
if (collection && COLLECTIONS[collection]) {
return `${base}/collection/${COLLECTIONS[collection]}/${width}x${height}`;
}
if (query) {
return `${base}/${width}x${height}/?${encodeURIComponent(query)}`;
}
return `${base}/random/${width}x${height}`;
}
/**
* Get a gaming-themed background
*/
export function getGamingBackground(width = 1920, height = 1080) {
return getUnsplashImage({ width, height, query: 'gaming,neon,dark' });
}
/**
* Get a tech-themed background
*/
export function getTechBackground(width = 1920, height = 1080) {
return getUnsplashImage({ width, height, query: 'technology,dark,abstract' });
}
/**
* Get a random avatar placeholder
* Uses specific seeds for consistency
*/
export function getAvatarImage(seed, size = 200) {
// Use DiceBear for avatars (more reliable than Unsplash for small images)
const styles = ['adventurer', 'avataaars', 'bottts', 'fun-emoji', 'lorelei', 'notionists', 'personas'];
const style = styles[Math.abs(hashCode(seed)) % styles.length];
return `https://api.dicebear.com/7.x/${style}/svg?seed=${encodeURIComponent(seed)}&size=${size}`;
}
/**
* Get abstract pattern for cards/backgrounds
*/
export function getAbstractPattern(width = 800, height = 600) {
return getUnsplashImage({ width, height, query: 'abstract,gradient,dark' });
}
/**
* Prebuilt image URLs for specific use cases
*/
export const PRESET_IMAGES = {
heroBackground: 'https://images.unsplash.com/photo-1538481199705-c710c4e965fc?w=1920&q=80', // Gaming setup
loginBackground: 'https://images.unsplash.com/photo-1550745165-9bc0b252726f?w=1920&q=80', // Retro gaming
chatBackground: 'https://images.unsplash.com/photo-1614850523459-c2f4c699c52e?w=1920&q=80', // Dark abstract
serverBanner: 'https://images.unsplash.com/photo-1542751371-adc38448a05e?w=1200&q=80', // Esports
profileBanner: 'https://images.unsplash.com/photo-1511512578047-dfb367046420?w=1200&q=80', // Gaming aesthetic
defaultAvatar: 'https://images.unsplash.com/photo-1566577134770-3d85bb3a9cc4?w=400&q=80', // Abstract
voiceChannel: 'https://images.unsplash.com/photo-1598488035139-bdbb2231ce04?w=800&q=80', // Audio waves
premiumBanner: 'https://images.unsplash.com/photo-1557682250-33bd709cbe85?w=1200&q=80', // Purple gradient
};
/**
* Simple hash function for consistent results
*/
function hashCode(str) {
let hash = 0;
for (let i = 0; i < str.length; i++) {
const char = str.charCodeAt(i);
hash = ((hash << 5) - hash) + char;
hash = hash & hash;
}
return hash;
}
export default {
getUnsplashImage,
getGamingBackground,
getTechBackground,
getAvatarImage,
getAbstractPattern,
PRESET_IMAGES,
COLLECTIONS,
};