foxbot icon indicating copy to clipboard operation
foxbot copied to clipboard

Twitter images to default

Open composingliger opened this issue 2 years ago • 2 comments

By default Twitter presents images at "medium" size, but it is possible to obtain a higher quality "original" with the :orig name.

Note: Twitter will resize the image at upload time so that no one edge is greater than 4096 px.

It looks like Syfaro/tgbotapi-rs@3bdfa356c51aca7feeccb84e6df520479d9b78fd caused one of the unit tests to start failing, so committed a fix.

composingliger avatar Aug 26 '22 04:08 composingliger

Hey, sorry about taking so long on getting back to this. I like the idea of fetching higher quality images, but from what I've seen, not every image has an orig quality. To ensure that images always work, there'd probably have to be a check first that the file exists. I can probably add that to this PR when I get a chance.

Syfaro avatar Nov 15 '22 20:11 Syfaro

Thanks for the reply! I'd forgotten about this PR. (And no worries! - I know people get busy with work/life/other stuff)

Interesting. So most new image URLs seem to be dynamic. For example:

  • https://pbs.twimg.com/media/FhcRvNiVEAAcaOA?format=jpg&name=orig
  • https://pbs.twimg.com/media/FhcRvNiVEAAcaOA?format=jpg&name=thumb
  • https://pbs.twimg.com/media/FhcRvNiVEAAcaOA?format=webp&name=large
  • https://pbs.twimg.com/media/FhcRvNiVEAAcaOA?format=png&name=large (JPEG re-encoded to PNG 😱)

Though there seems to be also image URLs that can't be used this way:

  • https://pbs.twimg.com/media/Bu4G7k3CcAA6Nx7?format=jpg&name=thumb ❌
  • https://pbs.twimg.com/media/Bu4G7k3CcAA6Nx7?format=jpg&name=medium ✔️
  • https://pbs.twimg.com/media/Bu4G7k3CcAA6Nx7?format=jpg&name=large ❌

(I wish I could find the original Tweet to see what the API returns for "sizes")

I'm not sure the best place to handle this fallback. Might need to do a HEAD request to check it exists?

composingliger avatar Nov 16 '22 08:11 composingliger