Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

193
Vistas
Horizontal Scaling Formula Issues

I'm currently working with image generation, and have stumbled across an issue that's left me stumped for a few hours. Here's a brief explanation. Below are two profile pictures (tributes) with their respective districts hovering above them. In the case of two tributes, the district text will center above them as shown below.

enter image description here

In the case of more than two, the first two tributes should have the District centered between them, while the last person has it centered above them.

enter image description here

In terms of code, I've found a way to detect such cases. But haven't figured out how the textDestinationX could use the loop to calculate the desired position of the text.

drawDistrictText(ctx, tributeArray) {
        ctx.font = 'bold 28px arial';
        ctx.textBaseline = 'alphabetic';
        ctx.fillStyle = '#ffffff';
        ctx.textAlign = 'center';

        const districtCount = Math.max(Math.ceil(tributeArray.length / 2), 2);
        let textDestinationX;
        let textDestinationY = avatarPaddingY - 15;

        for (let i = 0; i < districtCount; i++) {
            const districtText = `District ${i + 1}`;

            /* detecting if we are on our last iteration,
              and if the total length is odd, meaning there
               must be a district with one user. or if there
               is only 2 tributes.
            */

            if ((i === districtCount - 1 && tributeArray.length % 2 === 1) || tributeArray.length === 2) {
                console.log('center');
            } else {
                console.log('between');
            }

            /* After every 6 tributes, Y position is shifted down
               for the next row. The X position would need to be
               set to it's original position.
            */

            if ((i + 1) % 3 === 0) {
                textDestinationY += avatarSize + avatarSpacingY;
            }
        }
    }
about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda