feat: background resolution is now automatic and more accurate

This commit is contained in:
David Ralph
2021-07-12 21:48:08 +01:00
parent 99ffc82de0
commit c07d7ecbb0
4 changed files with 21 additions and 13 deletions

View File

@@ -135,8 +135,7 @@ export default class Background extends React.PureComponent {
photoInfo: { photoInfo: {
credit: favourited.credit, credit: favourited.credit,
location: favourited.location, location: favourited.location,
camera: favourited.camera, camera: favourited.camera
resolution: favourited.resolution
} }
}); });
} }
@@ -191,7 +190,6 @@ export default class Background extends React.PureComponent {
credit: credit, credit: credit,
location: data.location, location: data.location,
camera: data.camera, camera: data.camera,
resolution: data.resolution,
url: data.file, url: data.file,
photographerURL: photographerURL, photographerURL: photographerURL,
photoURL: photoURL photoURL: photoURL
@@ -369,7 +367,7 @@ export default class Background extends React.PureComponent {
<> <>
<div style={{ WebkitFilter: `blur(${localStorage.getItem('blur')}px) brightness(${localStorage.getItem('brightness')}%) ${backgroundFilter ? backgroundFilter + '(' + localStorage.getItem('backgroundFilterAmount') + '%)' : ''}` }} id='backgroundImage'/> <div style={{ WebkitFilter: `blur(${localStorage.getItem('blur')}px) brightness(${localStorage.getItem('brightness')}%) ${backgroundFilter ? backgroundFilter + '(' + localStorage.getItem('backgroundFilterAmount') + '%)' : ''}` }} id='backgroundImage'/>
{(this.state.photoInfo.credit !== '') ? {(this.state.photoInfo.credit !== '') ?
<PhotoInformation className={this.props.photoInformationClass} info={this.state.photoInfo} api={this.state.currentAPI}/> <PhotoInformation className={this.props.photoInformationClass} info={this.state.photoInfo} api={this.state.currentAPI} url={this.state.url}/>
: null} : null}
</> </>
); );

View File

@@ -7,8 +7,8 @@ import StarIcon2 from '@material-ui/icons/StarBorder';
export default class Favourite extends React.PureComponent { export default class Favourite extends React.PureComponent {
buttons = { buttons = {
favourited: <StarIcon onClick={this.favourite} className='topicons' />, favourited: <StarIcon onClick={() => this.favourite()} className='topicons' />,
unfavourited: <StarIcon2 onClick={this.favourite} className='topicons' /> unfavourited: <StarIcon2 onClick={() => this.favourite()} className='topicons' />
} }
constructor() { constructor() {
@@ -18,7 +18,7 @@ export default class Favourite extends React.PureComponent {
}; };
} }
favourite = () => { favourite() {
if (localStorage.getItem('favourite')) { if (localStorage.getItem('favourite')) {
localStorage.removeItem('favourite'); localStorage.removeItem('favourite');
this.setState({ this.setState({
@@ -36,8 +36,7 @@ export default class Favourite extends React.PureComponent {
url: url, url: url,
credit: document.getElementById('credit').textContent, credit: document.getElementById('credit').textContent,
location: document.getElementById('infoLocation').textContent, location: document.getElementById('infoLocation').textContent,
camera: document.getElementById('infoCamera').textContent, camera: document.getElementById('infoCamera').textContent
resolution: document.getElementById('infoResolution').textContent
})); }));
this.setState({ this.setState({

View File

@@ -1,3 +1,5 @@
import React from 'react';
import Info from '@material-ui/icons/Info'; import Info from '@material-ui/icons/Info';
import Location from '@material-ui/icons/LocationOn'; import Location from '@material-ui/icons/LocationOn';
import Camera from '@material-ui/icons/PhotoCamera'; import Camera from '@material-ui/icons/PhotoCamera';
@@ -22,6 +24,9 @@ const downloadImage = async (info) => {
}; };
export default function PhotoInformation(props) { export default function PhotoInformation(props) {
const [width, setWidth] = React.useState(0);
const [height, setHeight] = React.useState(0);
const language = window.language.widgets.background; const language = window.language.widgets.background;
if (props.info.hidden === true || !props.info.credit) { if (props.info.hidden === true || !props.info.credit) {
@@ -45,6 +50,14 @@ export default function PhotoInformation(props) {
} }
} }
// get resolution
const img = new Image();
img.onload = function() {
setWidth(this.width);
setHeight(this.height);
}
img.src = props.url;
return ( return (
<div className='photoInformation'> <div className='photoInformation'>
<h1>{photo} <span id='credit'>{credit}</span></h1> <h1>{photo} <span id='credit'>{credit}</span></h1>
@@ -58,7 +71,7 @@ export default function PhotoInformation(props) {
<Camera/> <Camera/>
<span id='infoCamera'>{props.info.camera || 'N/A'}</span> <span id='infoCamera'>{props.info.camera || 'N/A'}</span>
<Resolution/> <Resolution/>
<span id='infoResolution'>{props.info.resolution || 'N/A'}</span> <span id='infoResolution'>{width}x{height}</span>
<Photographer/> <Photographer/>
<span>{photographer}</span> <span>{photographer}</span>
{(localStorage.getItem('downloadbtn') === 'true') && !props.info.offline && !props.info.photographerURL ? {(localStorage.getItem('downloadbtn') === 'true') && !props.info.offline && !props.info.photographerURL ?

View File

@@ -22,9 +22,7 @@ export default class Clock extends React.PureComponent {
this.timer = setTimeout(() => { this.timer = setTimeout(() => {
const now = new Date(); const now = new Date();
const timeType = localStorage.getItem('timeType'); switch (localStorage.getItem('timeType')) {
switch (timeType) {
case 'percentageComplete': case 'percentageComplete':
this.setState({ this.setState({
time: (now.getHours() / 24).toFixed(2).replace('0.', '') + '%' time: (now.getHours() / 24).toFixed(2).replace('0.', '') + '%'