From cddb7ccc8cef479603e6aeacba4259425b7ca257 Mon Sep 17 00:00:00 2001 From: Ben Gotow Date: Tue, 3 Apr 2018 18:32:04 -0700 Subject: [PATCH] Apply explicit width and height to gravatar/twitter signature images --- .../composer-signature/lib/constants.es6 | 8 +++++--- .../composer-signature/lib/signature-photo-picker.jsx | 2 +- .../composer-signature/lib/templates.es6 | 10 +++++----- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/internal_packages/composer-signature/lib/constants.es6 b/app/internal_packages/composer-signature/lib/constants.es6 index 2130b6c79..004e1e274 100644 --- a/app/internal_packages/composer-signature/lib/constants.es6 +++ b/app/internal_packages/composer-signature/lib/constants.es6 @@ -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') { diff --git a/app/internal_packages/composer-signature/lib/signature-photo-picker.jsx b/app/internal_packages/composer-signature/lib/signature-photo-picker.jsx index c14f648a7..2c362c0ba 100644 --- a/app/internal_packages/composer-signature/lib/signature-photo-picker.jsx +++ b/app/internal_packages/composer-signature/lib/signature-photo-picker.jsx @@ -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' }, }); }; diff --git a/app/internal_packages/composer-signature/lib/templates.es6 b/app/internal_packages/composer-signature/lib/templates.es6 index ac1810ad7..384e5966d 100644 --- a/app/internal_packages/composer-signature/lib/templates.es6 +++ b/app/internal_packages/composer-signature/lib/templates.es6 @@ -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