$max + self::TOLERANCE ) { /* translators: 1: widest accepted shape, 2: this image's shape. */ return sprintf( __( 'images can be no wider than %1$s, and this one is %2$s.', 'orbitwrite' ), self::label( $max ), self::label( $ratio ) ); } return null; } /** * A ratio as people write it: 0.8 → "4:5", 1.91 → "1.91:1". * * @param float $ratio Width ÷ height. */ public static function label( float $ratio ): string { foreach ( array( 1, 2, 3, 4, 5, 9, 16 ) as $height ) { $width = $ratio * $height; if ( abs( $width - round( $width ) ) < 0.02 && round( $width ) <= 21 ) { return (int) round( $width ) . ':' . $height; } } return rtrim( rtrim( number_format( $ratio, 2, '.', '' ), '0' ), '.' ) . ':1'; } }