import { useState, Fragment } from 'react'; import { Info, LocationOn, PhotoCamera, Crop as Resolution, Person as Photographer, GetApp as Download } from '@material-ui/icons'; import Hotkeys from 'react-hot-keys'; const toDataURL = async (url) => { const res = await fetch(url); return URL.createObjectURL(await res.blob()); }; const formatText = (text) => { return text.toLowerCase().replaceAll(',', '').replaceAll(' ', '-'); }; const downloadImage = async (info) => { const link = document.createElement('a'); link.href = await toDataURL(info.url); link.download = `mue-${formatText(info.credit)}-${formatText(info.location)}.jpg`; document.body.appendChild(link); link.click(); document.body.removeChild(link); window.stats.postEvent('feature', 'Background download'); }; export default function PhotoInformation(props) { const [width, setWidth] = useState(0); const [height, setHeight] = useState(0); const language = window.language.widgets.background; if (props.info.hidden === true || !props.info.credit) { return null; } // remove unsplash and pexels text const photographer = props.info.credit.split(` ${language.unsplash}`)[0].split(` ${language.pexels}`); let credit = props.info.credit; let photo = language.credit; // unsplash and pexels credit if (props.info.photographerURL && props.info.photographerURL !== '' && !props.info.offline && props.api) { if (props.api === 'unsplash') { photo = {language.credit}; credit = <>{photographer} {language.unsplash}>; } else { photo = {language.credit}; credit = <>{photographer} {language.pexels}>; } } // get resolution const img = new Image(); img.onload = (event) => { setWidth(event.target.width); setHeight(event.target.height); }; img.src = (localStorage.getItem('ddgProxy') === 'true' && !props.info.offline && !props.url.startsWith('data:')) ? window.constants.DDG_IMAGE_PROXY + props.url : props.url; // info is still there because we want the favourite button to work if (localStorage.getItem('photoInformation') === 'false') { return (