Download the PHP package bakame/shoe-size-converter without Composer
On this page you can find all versions of the php package bakame/shoe-size-converter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bakame/shoe-size-converter
More information about bakame/shoe-size-converter
Files in bakame/shoe-size-converter
Package shoe-size-converter
Short Description shoe-size converter library for PHP
License MIT
Informations about the package shoe-size-converter
Bakame Shoe Sizes Converter
This small application was prompted by the following post https://phpc.social/@[email protected]/117123893682362282
Converting shoes size is difficult, too difficult!!

I discovered schuhgroessen-umrechner and, inspired by Sarah's excellent work, built this small library as an independent reimplementation.
System Requirements
- PHP >= 8.4 is required but the latest stable version of PHP is recommended.
[!IMPORTANT] If the conversion data is stored in a CSV file you will have to install
league/csv>= 9.28If the conversion data is stored in a database,
ext-pdosupport is required.
Installation
Shoe size converter is available on Packagist and can be installed using Composer:
composer require bakame/shoe-size-converter
The SPA
The original script by Sarah Amft has been reimplemented using this library's API
and is available in the public directory. It provides a small single-page application
for converting adult and children's shoe sizes between supported shoe size systems.
To run the converter locally:
- Install this repo via git clone,
- Run
composer install - Change to the
publicdirectory inside the root directory, - Start PHP's built-in development server:
`
Then open http://localhost:4000/ in your browser.
The application allows you to convert both adult and children's shoe sizes.
The CLI command
The package also provides a command-line converter.
To run the CLI command locally:
- Install this repo via composer
This returns:
The first argument is the input shoe size unit, followed by the shoe size value. For example:
You can specify the shoe size system using the --type or -t option. The
supported values are adults and children. The adults system is used by
default when no type is explicitly specified.
| Option | Description | Default |
|---|---|---|
--type, -t |
Shoe size system: adults or children |
adults |
The Library
Create a shoe size using one of the supported units:
Both instances expose their numeric value and unit:
[!IMPORTANT] Adult and children's shoe sizes differ in how their conversions are determined. Adult shoe sizes can be converted using deterministic foot-length-based formulas, whereas children's shoe sizes MUST use a specific conversion table.
Adult shoe size conversions
Calculated conversions
AdultSize supports deterministic shoe-size calculations based on foot length.
You can calculate an equivalent shoe size in any supported adult unit using
AdultSize::in():
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 adult equivalents at once with
AdultSize::equivalents():
These calculation methods are only available for AdultSize. Children's shoe
sizes cannot be calculated using foot-length-based formulas and therefore must
be converted using the conversion table.
Physical measurements
An AdultSize can also be represented by its physical foot measurement via its
dedicated $footLength property, expressed as a Bakame\Shoes\Length.
The Length class allows converting the length to millimeters, centimeters,
or inches:
These measurements are calculated from the shoe size's foot length and are independent of the conversion lookup table.
Adult shoe sizes can be compared by their physical foot length using
Length::compare(). This compares the underlying measurement, regardless of
the shoe-size system or length unit:
The comparison returns a negative value when the first shoe is shorter, 0
when both shoes have the same foot length, and a positive value when the first
shoe is longer.
For children's shoe sizes, where a foot-length calculation cannot be used,
Converter::footLength() retrieves the corresponding measurement from the
conversion table:
Converter can also be used for adult shoe sizes. When an adult size or
measurement is not available in the conversion table, Converter falls back
to the corresponding calculation.
This means that Converter::size() and Converter::footLength() can be used
with both adult and children's shoe sizes while preserving the appropriate
conversion strategy for each system.
ISO 19407:2023-based conversions
If you want to use the provided conversion data, use Converter.
Converter::size() and Converter::equivalents() use the configured conversion
table and fall back to the calculation algorithm when converting an AdultSize
if the required data is not available. For ChildSize, the conversion table is
the only source of conversion data.
These methods can be used for both adult and children's shoe sizes, provided
that the Converter is configured with the corresponding ShoeType.
For example:
Or retrieve all available equivalents:
If no equivalent is present in the conversion table, Converter falls back to
the calculation algorithm for AdultSize. For ChildSize, no equivalent can
be calculated, so null is returned when no matching entry is found.
| Adult | Children | |
|---|---|---|
AdultSize::footLength |
Calculation | Not available |
AdultSize::in() |
Calculation | Not available |
AdultSize::equivalents() |
Calculation | Not available |
Converter::footLength() |
Table, then calculation | Table only |
Converter::size() |
Table, then calculation | Table only |
Converter::equivalents() |
Table, then calculation | Table only |
Persistence Layer
The converter can be created using one of the following data sources:
- a CSV file path or file stream;
- a PDO connection; or
- no data source, in which case the default conversion table is used.
When a file path or stream is provided, it must reference a valid CSV file with
the expected structure for the selected ShoeType. When a PDO connection is
provided, the database must contain the appropriate conversion table with the
expected columns for the selected ShoeType.
The expected structure depends on the shoe size system:
- Adults —
eu,us_men,us_women,uk,cm, andmondopoint. - Children —
eu,us,uk,cm, andmondopoint.
For CSV sources, these names must be provided as the column headers in the first row. For PDO sources, the data must be stored in the corresponding table:
shoe_sizes_adultsforShoeType::Adults.shoe_sizes_childrenforShoeType::Children.
Both tables must use the expected columns for their respective shoe size system.
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 CONDUCT for details.
Security
If you discover any security related issues, please email [email protected] 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!