Updated palette algorithm

This commit is contained in:
dangered wolf 2022-07-25 19:52:10 -04:00
parent 046383f56b
commit 5afb9ffe37
No known key found for this signature in database
GPG key ID: 41E4D37680ED8B58
3 changed files with 16 additions and 4 deletions

View file

@ -78,7 +78,6 @@ const populateTweetProperties = async (
mediaList.forEach(media => {
let mediaObject = processMedia(media);
console.log('mediaObject', JSON.stringify(mediaObject));
if (mediaObject) {
if (mediaObject.type === 'photo') {
apiTweet.twitter_card = 'summary_large_image';
@ -86,7 +85,6 @@ const populateTweetProperties = async (
apiTweet.media.photos = apiTweet.media.photos || [];
apiTweet.media.photos.push(mediaObject);
console.log('media', apiTweet.media);
} else if (mediaObject.type === 'video' || mediaObject.type === 'gif') {
apiTweet.twitter_card = 'player';
apiTweet.media = apiTweet.media || {};

View file

@ -14,12 +14,22 @@ export const colorFromPalette = (palette: MediaPlaceholderColor[]) => {
const rgb = palette[i].rgb;
// We need vibrant colors, grey backgrounds won't do!
if (rgb.red + rgb.green + rgb.blue < 120) {
if (
rgb.red + rgb.green + rgb.blue < 120 ||
rgb.red + rgb.green + rgb.blue > 240 * 3
) {
continue;
}
return rgbToHex(rgb.red, rgb.green, rgb.blue);
}
/* If no other color passes vibrancy test (not too white or black)
Then we'll use the top color anyway. */
if (palette?.[0]?.rgb) {
console.log('falling back to top color regardless of vibrancy');
return rgbToHex(palette[0].rgb.red, palette[0].rgb.green, palette[0].rgb.blue);
}
return Constants.DEFAULT_COLOR;
};

View file

@ -4,7 +4,6 @@ import { sanitizeText } from './utils';
import { Strings } from './strings';
import { getAuthorText } from './author';
import { statusAPI } from './api';
import { calculateTimeLeftString } from './pollHelper';
export const returnError = (error: string): StatusResponse => {
return {
@ -63,6 +62,7 @@ export const handleStatus = async (
}
}
/* Use quote media if there is no media */
if (!tweet.media && tweet.quote?.media) {
tweet.media = tweet.quote.media;
tweet.twitter_card = 'summary_large_image';
@ -79,6 +79,7 @@ export const handleStatus = async (
`<meta name="twitter:title" content="${tweet.author.name} (@${tweet.author.screen_name})"/>`
];
/* Video renderer */
if (tweet.media?.video) {
authorText = encodeURIComponent(tweet.text || '');
@ -97,6 +98,7 @@ export const handleStatus = async (
);
}
/* Photo renderer */
if (tweet.media?.photos) {
const { photos } = tweet.media;
let photo = photos[mediaNumber || 0];
@ -145,6 +147,7 @@ export const handleStatus = async (
);
}
/* External media renderer (i.e. YouTube) */
if (tweet.media?.external) {
const { external } = tweet.media;
headers.push(
@ -162,6 +165,7 @@ export const handleStatus = async (
let siteName = Constants.BRANDING_NAME;
let newText = tweet.text;
/* Poll renderer */
if (tweet.poll) {
const { poll } = tweet;
let barLength = 34;