Get optimized images

This commit is contained in:
Mosh Hamedani 2023-03-01 09:29:01 -08:00
parent 9a9eb5d2a6
commit e3ec9810f8
2 changed files with 10 additions and 1 deletions

View file

@ -1,6 +1,7 @@
import { Card, CardBody, Heading, HStack, Image, Text } from '@chakra-ui/react'
import React from 'react'
import { Game } from '../hooks/useGames'
import getCroppedImageUrl from '../services/image-url'
import CriticScore from './CriticScore'
import PlatformIconList from './PlatformIconList'
@ -11,7 +12,7 @@ interface Props {
const GameCard = ({ game }: Props) => {
return (
<Card borderRadius={10} overflow='hidden'>
<Image src={game.background_image} />
<Image src={getCroppedImageUrl(game.background_image)} />
<CardBody>
<Heading fontSize='2xl'>{game.name}</Heading>
<HStack justifyContent='space-between'>

View file

@ -0,0 +1,8 @@
const getCroppedImageUrl = (url: string) => {
const target = 'media/';
const index = url.indexOf(target) + target.length;
return url.slice(0, index) + 'crop/600/400/' + url.slice(index);
}
export default getCroppedImageUrl;