Files
GNX-WEB/gnx-react/lib/imageUtils.ts
Iliyan Angelov fe26b7cca4 GNXSOFT.COM
2025-09-26 00:15:37 +03:00

37 lines
1.1 KiB
TypeScript

// Image utility functions
export const FALLBACK_IMAGES = {
BLOG: '/images/blog/blog-poster.png',
CASE_STUDY: '/images/case/poster.png',
SERVICE: '/images/service/thumb-one.png',
GALLERY: '/images/masonry/one.png',
BANNER: '/images/banner/banner-bg.png',
DEFAULT: '/images/logo.png'
};
export function getValidImageUrl(imageUrl?: string, fallback?: string): string {
if (!imageUrl || imageUrl.trim() === '') {
return fallback || FALLBACK_IMAGES.DEFAULT;
}
// If it's already a full URL, return as is
if (imageUrl.startsWith('http://') || imageUrl.startsWith('https://')) {
return imageUrl;
}
// If it starts with /, it's already a public path
if (imageUrl.startsWith('/')) {
return imageUrl;
}
// Otherwise, assume it's a public path and add /
return `/${imageUrl}`;
}
export function getImageAlt(title?: string, fallback: string = 'Image'): string {
return title ? `${title} - Image` : fallback;
}
// Export getValidImageAlt as an alias for getImageAlt for backward compatibility
export const getValidImageAlt = getImageAlt;