PHPackages                             resohead/filesize - 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. resohead/filesize

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

resohead/filesize
=================

Convert file sizes to/from different units with a fluent API - like Carbon but for file size.

0.2.0(4y ago)043MITPHPPHP ^8.0

Since Aug 7Pushed 4y ago1 watchersCompare

[ Source](https://github.com/resohead/Filesize)[ Packagist](https://packagist.org/packages/resohead/filesize)[ Docs](https://github.com/resohead/filesize)[ RSS](/packages/resohead-filesize/feed)WikiDiscussions main Synced 5d ago

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

Filesize
========

[](#filesize)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d75e735e66a1ef3892e3ec580ad8f0375e4e217814b6a2c4680cbbe089b5e130/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7265736f686561642f66696c6573697a652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/resohead/filesize)[![Total Downloads](https://camo.githubusercontent.com/74e6949527fb787dd1657702052b8ab3386e481ab1a508062cbb1ecd25781af7/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f7265736f686561642f66696c6573697a652e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/resohead/filesize)

PHP fluent API extension for converting file sizes - like Carbon but for file sizes.

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

[](#installation)

You can install the package via composer:

```
composer require resohead/filesize
```

Usage
-----

[](#usage)

### Basics

[](#basics)

```
$filesize = new Filesize;
```

```
$filesize->from(1200)->toKilobytes()->asNumber(); // 1.0
$filesize->fromBytes(1200)->toKilobytes()->asNumber(2); // 1.2
$filesize->fromBytes(1200)->toKibibytes()->asNumber(2); // 1.17

$filesize->fromKilobytes(1)->toKibibytes()->round(3)->asNumber(); // 0.977
$filesize->fromKilobytes(1)->toBytes()->asInteger(); // 1000

$filesize->fromKibibytes(1)->toBytes()->asInteger(); // 1024

$filesize->fromBytes(1024)->toKilobytes()->round(3)->asNumber(); //1.024
$filesize->fromBytes(1000)->toKilobytes()->round(3)->asNumber(); //1.000

$filesize->fromBytes(1024)->toKibibytes()->round(3)->asNumber(); //1.000
$filesize->fromBytes(1000)->toKibibytes()->round(3)->asNumber(); //0.977

$filesize->fromKilobytes(1.2)->asNumber(); // 1200
$filesize->fromKilobytes(1.2)->toSame()->asNumber(); // 1.2

$filesize->fromGigabytes(5000))
        ->toTerabytes()
        ->asNumber(2); // 5.0

$filesize->fromGibibytes(5000))
        ->toTebibytes()
        ->asNumber(2); // 4.88

$filesize->fromGigabytes(1)
    ->toMegabytes()
    ->round(3)
    ->withThousandSeparator() // optional - default: ","
    ->withDecimalSeparator() // optional - default: "."
    ->asString(); // "1,073.742 MB"
```

### For Humans

[](#for-humans)

This will automatically convert the given size to the most useful human format (defaults to decmial, i.e. GB)

```
$filesize->fromBytes(1073741824)->round(2)->forHumans(); // "1.07 GB"

$filesize->fromGigabytes(0.5)->forHumans(); // "512 MB"

$filesize->fromBytes(15000)->inBinary()->round(1)->forHumans(); // '15.0 kB', or
$filesize->fromBytes(15000)->inBinary()->round(1)->forHumans(); // '14.6 KiB', or
$filesize->fromBytes(15000)->toKibibytes()->round(1)->forHumans(); // '14.6 KiB'

$filesize->fromBytes(15000)->inDecimal()->round(1)->forHumans(); // '15.0 kB', or
$filesize->fromBytes(15000)->toKibibytes()->round(1)->forHumans(); // '15.0 kB'

$filesize->fromBytes(1073741824)->inDecimal()->forHumans(); // "1.00 GiB"
$filesize->fromBytes(1073741824)->toKibtyes()->forHumans(); // "1.00 GiB"
$filesize->fromBytes(1073741824)->toMegabytes()->forHumans(); // "1.07 GB"
$filesize->fromBytes(1073741824)->inDecimal()->forHumans(); // "1.07 GB"

$filesize->fromMegabytes(56156113)->forHumans(); // "53.55 TB"
```

### Parse input from string

[](#parse-input-from-string)

```
Filesize::parse('1 KB')->toBytes()->asInteger(); // 1024
Filesize::parse('1 KB')->toKilobytes()->asString(); // "1 kB"
Filesize::parse('1 KB')->round(3)->toMb()->asString(); // "0.001 MB"
```

### Testing

[](#testing)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity47

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

Every ~1 days

Total

2

Last Release

1743d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/36e24fbccf4832f90d9bec1405989c63a8f8c12692e8be90c16a9a38867ab8aa?d=identicon)[resohead](/maintainers/resohead)

---

Top Contributors

[![resohead](https://avatars.githubusercontent.com/u/13508056?v=4)](https://github.com/resohead "resohead (8 commits)")

---

Tags

conversionbytesfilesizeresohead

###  Code Quality

TestsPest

### Embed Badge

![Health badge](/badges/resohead-filesize/health.svg)

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

###  Alternatives

[cuyz/valinor

Dependency free PHP library that helps to map any input into a strongly-typed structure.

1.5k9.2M108](/packages/cuyz-valinor)[florianv/swap

Exchange rates library for PHP

1.3k6.4M16](/packages/florianv-swap)[spatie/color

A little library to handle color conversions

38018.9M28](/packages/spatie-color)[php-units-of-measure/php-units-of-measure

A PHP library for converting between standard units of measure.

3123.4M20](/packages/php-units-of-measure-php-units-of-measure)[florianv/laravel-swap

Currency exchange rates library for Laravel and Lumen

3342.0M2](/packages/florianv-laravel-swap)[php-unit-conversion/php-unit-conversion

A fully PSR-4 compatible PHP library for converting between standard units of measure.

681.2M1](/packages/php-unit-conversion-php-unit-conversion)

PHPackages © 2026

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