bestofjs / javascript-risingstars

:stars: An overview of the JavaScript landscape in 2023: trends about frontend, Node.js, fullstack frameworks, build tools, testing, Vue.js, React, state management...
https://risingstars.js.org
1.02k stars 56 forks source link

Project avatars are blurry #8

Closed SachaG closed 6 years ago

SachaG commented 6 years ago

https://d3vv6lp55qjaqc.cloudfront.net/items/1x3l1S3n1B2W0N1F3r1H/Screen%20Shot%202017-12-28%20at%2019.47.39.png?X-CloudApp-Visitor-Id=43642&v=eabf3cd0

Doesn't look very good… Can we use a larger size (1.5x or 2x display size) or is that the only size available from GitHub? If we can't use larger images we should reduce the dimensions of the image when displayed.

michaelrambeau commented 6 years ago

For a few projects projects, including VS Code and React, I use SVG files hosted on bestof.js.org, so that's why VS Code icon looks nice. But for the majority of the projects, it's the GitHub repo owner avatar that is used, for example: https://avatars.githubusercontent.com/u/1778935?v=3&s=50

The last parameter s=50 means a size of 50 pixels, so it means we can request any size from GitHub.

Could we request the 100 pixels wide icon for retina screens and the 50 pixels wide icon for other screens, using the technique of "responsive images" ?

SachaG commented 6 years ago

We could do responsive images if we load them dynamically via JS. Which might be a good idea anyway to speed up the initial load. But if we have to pick just one size then I'd say 100, or 75 if that's too big (there's not a huge visible difference between 1.5x and 2x at these small sizes).

michaelrambeau commented 6 years ago

I don't think JavaScript is required, I thought about using the technique described in this article http://alistapart.com/article/responsive-images-in-practice:

<img src="standard.jpg" srcset="retina.jpg 2x, super-retina.jpg 3x" />

I'm checking if it works...

michaelrambeau commented 6 years ago

This commit seems to have fixed the problem, icons are no more blurry on my Android phone.

Could you confirm it works for you too?

const Avatar = ({ project, size = 100 }) => {
  const { svg } = project
  if (svg)
    return (
      <div style={{ width: size }} dangerouslySetInnerHTML={{ __html: svg }} />
    )
  const urls = {
    standard: getProjectAvatarUrl(project, size),
    retina: getProjectAvatarUrl(project, size * 2)
  }
  return (
    <img
      src={urls.standard}
      srcSet={`${urls.retina} 2x`}
      width={size}
      height={size}
      alt={project.name}
    />
  )
}