Apply explicit width and height to gravatar/twitter signature images

This commit is contained in:
Ben Gotow 2018-04-03 18:32:04 -07:00
parent e7ddad7862
commit cddb7ccc8c
3 changed files with 11 additions and 9 deletions

View file

@ -76,18 +76,20 @@ export const ResolveSignatureData = data => {
.createHash('md5')
.update((data.email || '').toLowerCase().trim())
.digest('hex');
data.photoURL = `https://www.gravatar.com/avatar/${hash}`;
data.photoURL = `https://www.gravatar.com/avatar/${hash}/?s=160&msw=160&msh=160`;
}
if (data.photoURL === 'twitter') {
data.photoURL = `https://twitter.com/${data.twitterHandle}/profile_image?size=original`;
data.photoURL = `https://twitter.com/${
data.twitterHandle
}/profile_image?size=original&msw=128&msh=128`;
}
if (data.photoURL === 'company') {
const domain =
(data.websiteURL && URL.parse(data.websiteURL).hostname) ||
(data.email && data.email.split('@').pop());
data.photoURL = `https://logo.clearbit.com/${domain}`;
data.photoURL = `https://logo.clearbit.com/${domain}?msw=128&msh=128`;
}
if (data.photoURL === 'custom') {

View file

@ -119,7 +119,7 @@ export default class SignaturePhotoPicker extends React.Component {
}
this.props.onChange({
target: { value: `${link}?t=${Date.now()}&w=${width}&h=${height}`, id: 'photoURL' },
target: { value: `${link}?t=${Date.now()}&msw=${width}&msh=${height}`, id: 'photoURL' },
});
};

View file

@ -26,17 +26,17 @@ function widthAndHeightForPhotoURL(photoURL, { maxWidth, maxHeight } = {}) {
}
let q = {};
try {
q = querystring.parse(photoURL);
q = querystring.parse(photoURL.split('?').pop());
} catch (err) {
return {};
}
if (!q.w || !q.h) {
if (!q.msw || !q.msh) {
return {};
}
const scale = Math.min(1, maxWidth / q.w, maxHeight / q.h);
const scale = Math.min(1, maxWidth / q.msw, maxHeight / q.msh);
return {
width: Math.round(q.w * scale),
height: Math.round(q.h * scale),
width: Math.round(q.msw * scale),
height: Math.round(q.msh * scale),
};
}
// Generic components used across templates