PHPackages                             alto/scale - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. alto/scale

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

alto/scale
==========

A nano package for computing and manipulating modular scales (typography, rhythm, grids).

v1.0.0(5mo ago)10MITPHPPHP ^8.4CI passing

Since Jan 16Pushed 5mo agoCompare

[ Source](https://github.com/PhpAlto/scale)[ Packagist](https://packagist.org/packages/alto/scale)[ Docs](https://github.com/phpalto/scale)[ GitHub Sponsors](https://github.com/sponsors/smnandre)[ RSS](/packages/alto-scale/feed)WikiDiscussions main Synced today

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

Alto \\ Scale
=============

[](#alto--scale)

A strict, mathematical engine for **Modular Scales**. It handles the arithmetic of progressions, designed for generative design, typography engines, and rhythmic computation.

---

 [![PHP Version](https://camo.githubusercontent.com/7aa833a6cc9f90d5bb1c11f4ce0f2455d91a23b0a960a9b23df85164962731e2/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048502d382e342b2d6666656664663f6c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d303030)](https://github.com/PhpAlto/scale) [![Packagist Version](https://camo.githubusercontent.com/a7ab2e57144afcfb7e0d31cc2058bf5386a59e285b2d1b9d82e9d88be254b15b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f616c746f2f7363616c653f6c6162656c3d537461626c65266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30303026636f6c6f723d666665666466)](https://packagist.org/packages/alto/scale) [![CI](https://camo.githubusercontent.com/b9501552acfd3cd805fe23de4abd3859cfa6f2cff3be2b4be9cf6d9137927c86/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f506870416c746f2f7363616c652f43492e796d6c3f6272616e63683d6d61696e266c6162656c3d5465737473266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30303026636f6c6f723d666665666466)](https://github.com/PhpAlto/scale/actions) [![PHP Version](https://camo.githubusercontent.com/79820ea4fbf7ba81b487f71ba6cd7cc3990b572b950544e8be10876f72a81ba7/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f504850556e69742d3130302532352d6666656664663f6c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d303030)](https://github.com/PhpAlto/scale) [![PHP Version](https://camo.githubusercontent.com/46cab1ca7fbef6e1ecb3fcb46ebda03c929e31a141d14b601a9ecbfc868873d5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f5048505374616e2d4c564c25323031302d6666656664663f6c6f676f436f6c6f723d7768697465266c6162656c436f6c6f723d303030)](https://github.com/PhpAlto/scale) [![License](https://camo.githubusercontent.com/31f302776754608fb8705679fd2334612dc83fd0ec0d630f087982458d807804/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f506870416c746f2f7363616c653f6c6162656c3d4c6963656e7365266c6f676f436f6c6f723d7768697465266c6f676f53697a653d6175746f266c6162656c436f6c6f723d30303026636f6c6f723d666665666466)](./LICENSE)

Installation
------------

[](#installation)

```
composer require alto/scale
```

Core Concepts
-------------

[](#core-concepts)

### 1. The Scale Facade

[](#1-the-scale-facade)

Use the `Scale` facade for fluent instantiation of any scale type.

```
use Alto\Scale\Scale;
use Alto\Scale\Ratio;

// Modular (Geometric): Base 16px, Ratio 1.25 (Major Third)
$type = Scale::majorThird(16.0);

// Linear (Arithmetic): Base 0, Increment 8
$grid = Scale::linear(0, 8);

// Fibonacci: Using Binet's formula
$fib = Scale::fibonacci();

// Multi-Strand: Interleaved scales (e.g., 16px and 12px strands)
$strands = Scale::strands([16, 12], Ratio::PerfectFifth);
```

### 2. Computing Values

[](#2-computing-values)

All scales implement the `ScaleInterface` and are `IteratorAggregate`.

```
echo $type->get(0);  // 16.0
echo $type->get(1);  // 20.0
echo $type->get(-1); // 12.8

// ModularScale is callable
echo $type(2); // 25.0
```

#### Snapping (Normalization)

[](#snapping-normalization)

Find the nearest mathematical step for any arbitrary value.

```
// Returns 20.0 (The nearest step on a Major Third scale starting at 16)
$value = $type->snap(19.8);
```

#### Iteration &amp; Ranges

[](#iteration--ranges)

```
// Scales are iterable (defaults to steps 0-10)
foreach ($type as $step => $value) {
    // ...
}

// Custom ranges
$values = $type->range(-2, 2);
// Returns: [-2 => 10.24, -1 => 12.8, 0 => 16.0, 1 => 20.0, 2 => 25.0]
```

### 3. The Guesser (Reverse Engineering)

[](#3-the-guesser-reverse-engineering)

Analyze messy datasets to find their underlying mathematical scale.

```
use Alto\Scale\Scale;
use Alto\Scale\ScaleGuesser;

$messyValues = [15.9, 20.1, 24.8, 31.5];

// Via the facade
$scale = Scale::guess($messyValues);

// Or directly with custom tolerance
$guesser = new ScaleGuesser(tolerance: 0.05);
$scale = $guesser->guess($messyValues);

// Align values to the guessed (or provided) scale
$aligned = $guesser->align($messyValues);
```

### 4. The Linter (Audit &amp; Fix)

[](#4-the-linter-audit--fix)

Audit datasets for scale compliance and automatically harmonize them.

```
use Alto\Scale\ScaleLinter;
use Alto\Scale\Scale;

$linter = new ScaleLinter(Scale::linear(0, 8));

// Get a detailed compliance report
$report = $linter->lint([8, 15, 24]);
// Each entry: ['original', 'suggested', 'step', 'deviation', 'isValid']

// Returns [8.0, 16.0, 24.0]
$fixed = $linter->fix([8, 15, 24]);
```

API Reference
-------------

[](#api-reference)

### `Alto\Scale\Scale` (Facade)

[](#altoscalescale-facade)

MethodReturns`modular(float $base, float|Ratio $ratio)``ModularScale``linear(float $base, float $increment)``LinearScale``fibonacci(float $multiplier)``FibonacciScale``strands(array $bases, float|Ratio $ratio)``MultiStrandScale``guess(array $values)``ModularScale``majorThird(float $base)``ModularScale``perfectFifth(float $base)``ModularScale``golden(float $base)``ModularScale`### `Alto\Scale\ScaleInterface`

[](#altoscalescaleinterface)

All scale classes (`ModularScale`, `LinearScale`, `FibonacciScale`, `MultiStrandScale`) implement:

MethodDescription`get(int $step): float`Get the value at a specific step`stepOf(float $value): int`Find the closest step index for a value`snap(float $value): float`Snap a value to the nearest step`range(int $min, int $max): array`Generate values between steps### `Alto\Scale\ModularScale`

[](#altoscalemodularscale)

Geometric progression: `value = base * (ratio ^ step)`

MethodDescription`areHarmonic(float $a, float $b, float $epsilon): bool`Check if two values are harmonically related`withBase(float $base): self`Create a new scale with a different base`withRatio(float|Ratio $ratio): self`Create a new scale with a different ratio`shift(int $steps): self`Create a new scale shifted by N steps### `Alto\Scale\LinearScale`

[](#altoscalelinearscale)

Arithmetic progression: `value = base + (step * increment)`

### `Alto\Scale\FibonacciScale`

[](#altoscalefibonacciscale)

Fibonacci sequence using Binet's formula, with optional multiplier.

### `Alto\Scale\MultiStrandScale`

[](#altoscalemultistrandscale)

Interleaved modular scales sharing a common ratio, useful for multi-strand typographic scales.

### `Alto\Scale\ScaleGuesser`

[](#altoscalescaleguesser)

MethodDescription`guess(array $values): ModularScale`Infer a modular scale from values`align(array $values, ?ScaleInterface $scale): array`Snap all values to a scale### `Alto\Scale\ScaleLinter`

[](#altoscalescalelinter)

MethodDescription`lint(array $values): array`Audit values against a scale`fix(array $values): array`Harmonize values to the scale### `Alto\Scale\Ratio` (Enum)

[](#altoscaleratio-enum)

Standard musical/typographic ratios:

RatioValue`MinorSecond`1.067`MajorSecond`1.125`MinorThird`1.200`MajorThird`1.250`PerfectFourth`1.333`AugmentedFourth`1.414`PerfectFifth`1.500`MinorSixth`1.600`GoldenRatio`1.618`MajorSixth`1.667`MinorSeventh`1.778`MajorSeventh`1.875`Octave`2.000License
-------

[](#license)

This project is licensed under the [MIT License](./LICENSE).

###  Health Score

35

—

LowBetter than 77% of packages

Maintenance70

Regular maintenance activity

Popularity2

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

169d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/a8951d49b371d210280a58ce48969a07d1f49924810f8a1fab3a9343eb46fdc9?d=identicon)[simonandre](/maintainers/simonandre)

---

Top Contributors

[![smnandre](https://avatars.githubusercontent.com/u/1359581?v=4)](https://github.com/smnandre "smnandre (1 commits)")

---

Tags

design-tokensharmonic-scalemathematicalmodular-scalerythmscalescale-generatortypographygridscaletypographydesign-systemfibonaccirhythmmodular-scalegolden-ratiolinear-scalegeometric-progression

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/alto-scale/health.svg)

```
[![Health](https://phpackages.com/badges/alto-scale/health.svg)](https://phpackages.com/packages/alto-scale)
```

###  Alternatives

[desandro/masonry

Cascading grid layout library

16.7k436.4k4](/packages/desandro-masonry)[nicolaskruchten/pivottable

Javascript Pivot Table (aka Pivot Grid, Pivot Chart, Cross-Tab) implementation with drag'n'drop.

4.4k219.4k1](/packages/nicolaskruchten-pivottable)[kartik-v/yii2-grid

Yii 2 GridView on steroids. Various enhancements and utilities for the Yii 2.0 GridView widget.

5546.9M182](/packages/kartik-v-yii2-grid)[jolicode/jolitypo

Microtypography fixer for the web.

3511.1M5](/packages/jolicode-jolitypo)[michelf/php-smartypants

PHP SmartyPants

1165.8M39](/packages/michelf-php-smartypants)[drupol/phpermutations

Generators and iterators, permutations and combinations.

83717.2k5](/packages/drupol-phpermutations)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
