bakame/shoe-size-converter

shoesize converter library for PHP

Maintainers

Package info

github.com/bakame-php/shoes-size-converter

Documentation

pkg:composer/bakame/shoe-size-converter

Transparency log

Fund package maintenance!

nyamsprod

Statistics

Installs: 8

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

1.0.0 2026-08-22 12:58 UTC

This package is auto-updated.

Last update: 2026-08-22 12:59:13 UTC


README

This small library was prompted by the following post https://phpc.social/@nando161@partyon.xyz/117123893682362282

Converting shoes size is difficult, too difficult!!

Too many standards

I discovered schuhgroessen-umrechner and, inspired by Sarah's excellent work, built this small library as an independent reimplementation.

System Requirements

  • PHP >= 8.2 is required but the latest stable version of PHP is recommended.

Installation

Shoe size converter is available on Packagist and can be installed using Composer:

composer require bakame/shoe-size-converter

Usage

Create a shoe size using one of the supported units:

use Bakame\Shoes\Converter;
use Bakame\Shoes\Unit;

$euShoeSize = Unit::Eu->size(43);
// $euShoeSize is an instance of Bakame\Shoes\ShoeSize

A ShoeSize exposes its numeric value and unit:

$euShoeSize->value;
// 43

$euShoeSize->unit;
// Unit::Eu

Calculated conversions

You can calculate an equivalent shoe size in any supported unit using the foot-length-based conversion formulas:

$ukShoeSize = $euShoeSize->in(Unit::Uk);
// returns a ShoeSize containing the calculated UK size

$ukShoeSize->value;
// 9.5

$ukShoeSize->unit;
// Unit::Uk

The calculated value is the nearest size supported by the target sizing system. It is not a lookup in the ISO conversion table.

You can also calculate all supported equivalents at once with ShoeSize::equivalents():

$result = $euShoeSize->equivalents();
// returns an array containing the calculated equivalent shoe sizes
// for all supported units

Physical measurements

A ShoeSize can also be represented as a physical foot measurement. Dedicated methods are available for millimeters, centimeters, and inches:

$ukShoeSize->inMillimeters();
// 275

$ukShoeSize->inCentimeters();
// 27.5

$ukShoeSize->inInches();
// 10.826771653543

These measurements are derived from the calculated foot length and are independent of the conversion lookup table.

ISO 19407:2023-based conversions

If you require an exact equivalence from the provided conversion data rather than a calculated value, use Converter.

For example, when using the CSV persistence layer:

$path = __DIR__ . '/data/shoe_sizes.csv';

$converter = Converter::fromCsv($path);

Converter::availableSizes() returns the sizes available for a specific unit:

$converter->availableSizes(Unit::Eu);
// returns an iterator of ShoeSize instances
// containing all EU sizes available in the data source

You can retrieve all available equivalents for a shoe size using Converter::equivalents():

$result = $converter->equivalents($euShoeSize);
// returns the equivalent shoe sizes found in the lookup data

Or retrieve the equivalent for a specific unit with Converter::inUnit():

$ukShoeSize = $converter->inUnit($euShoeSize, Unit::Uk);
// returns the UK equivalent found in the lookup data

Unlike ShoeSize::in() and ShoeSize::equivalents(), these methods do not calculate missing values. They only return equivalences that are explicitly present in the configured persistence layer.

For example, a size may have no exact equivalent in the lookup data even though a calculated equivalent can be produced.

Please refer to the Persistence Layer section for information about the supported persistence layers and how to create and store the conversion data.

HTTP Endpoint

Warning

the HTTP endpoint is only available when the package has been cloned.

The original script by Sarah Amft has been reimplemented using this library's API in the api directory. It exposes the conversion functionality as an HTTP API endpoint that returns JSON responses. See converter.php.

To run the converter:

  • clone this repo,
  • go to the root directory,
  • and start PHP's built-in development server
php -S localhost:4000

Then open your browser or HTTP client and request:

http://localhost:4000/api/converter.php?unit=EU&size=42.5

This returns:

{"source":"calculated", "sizes":[{"value":270,"unit":"mondopoint"},{"value":27,"unit":"cm"},{"value":42.5,"unit":"eu"},{"value":9,"unit":"uk"},{"value":10,"unit":"us_men"},{"value":11,"unit":"us_women"}],"measurements":{"centimeters":27,"inches":10.62992125984252}}

in pretty print it gives:

{
    "source": "calculated",
    "sizes": [
        {
            "value": 270,
            "unit": "mondopoint"
        },
        {
            "value": 27,
            "unit": "cm"
        },
        {
            "value": 42.5,
            "unit": "eu"
        },
        {
            "value": 9,
            "unit": "uk"
        },
        {
            "value": 10,
            "unit": "us_men"
        },
        {
            "value": 11,
            "unit": "us_women"
        }
    ],
    "measurements": {
        "centimeters": 27,
        "inches": 10.6299212598425
    }
}

CLI command

Tip

the CLI command is always available.

vendor/bin/shoe-converter EU 42.5

This returns:

Shoe size conversion
Input
  eu 42.5
Sizes (calculated)
  mondopoint 270
  cm 27
  eu 42.5
  uk 9
  us_men 10
  us_women 11
Measurements
  27 cm
  10.629921259843 in

Persistence Layer

The package relies on the League\Csv\TabularData interface for reading shoe-size data. You can load data from either a CSV file or a database table.

Both sources must follow the expected shoe-size structure documented by the corresponding factory methods:

  • fromCsv() — loads data from a CSV file whose first row contains the eu, us_men, us_women, uk, cm and mondopoint column headers.
  • fromPdo() — loads data from a shoe_sizes database table containing the eu, us_men, us_women, uk, cm and mondopoint columns.

Important

The conversion table in the data directory is provided in CSV and SQLite formats and contains adult shoe-size conversions based on ISO 19407:2023.

Attribution

This library is an independent reimplementation inspired by schuhgroessen-umrechner by Sarah Amft.

The original project provided the reference for the shoe-size conversion functionality. The implementation, API, and examples have been completely rewritten as a standalone library.

All credit for the original work and inspiration goes to Sarah Amft.

Contributing

Contributions are welcome and will be fully credited. Please see CONTRIBUTING and CONDUCT for details.

Security

If you discover any security related issues, please email nyamsprod@gmail.com instead of using the issue tracker.

Changelog

Please see CHANGELOG for more information on what has changed recently.

Credits

License

The MIT License (MIT). Please see LICENSE for more information.

Happy Coding!