PHPackages                             jackardios/laravel-image-dimensions - 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. [File &amp; Storage](/categories/file-storage)
4. /
5. jackardios/laravel-image-dimensions

ActiveLibrary[File &amp; Storage](/categories/file-storage)

jackardios/laravel-image-dimensions
===================================

A Laravel package to efficiently determine image dimensions from local files, URLs, and Laravel storage.

v1.0.0(7mo ago)1291MITPHPCI passing

Since Sep 26Pushed 7mo agoCompare

[ Source](https://github.com/Jackardios/laravel-image-dimensions)[ Packagist](https://packagist.org/packages/jackardios/laravel-image-dimensions)[ Docs](https://github.com/Jackardios/laravel-image-dimensions)[ RSS](/packages/jackardios-laravel-image-dimensions/feed)WikiDiscussions main Synced 1mo ago

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

Laravel Image Dimensions
========================

[](#laravel-image-dimensions)

[![Latest Version on Packagist](https://camo.githubusercontent.com/d4ee94a2b178e2df6e330376acc90880d57786c7943dc283f19a3a2a8baac175/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6a61636b617264696f732f6c61726176656c2d696d6167652d64696d656e73696f6e732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/jackardios/laravel-image-dimensions)[![Tests](https://github.com/Jackardios/laravel-image-dimensions/actions/workflows/tests.yml/badge.svg)](https://github.com/Jackardios/laravel-image-dimensions/actions/workflows/tests.yml)

A robust and efficient Laravel package to get the dimensions (width and height) of images from various sources. It's designed to be fast, reliable, and easy to use, with built-in support for caching and optimized handling of remote files.

### Features

[](#features)

- **Multiple Sources**: Get dimensions from local file paths, remote URLs, and Laravel Storage disks.
- **Wide Format Support**: Supports common image formats like PNG, JPEG, GIF, WebP, and BMP.
- **Advanced SVG Parsing**: Correctly determines dimensions from SVGs, including those using `viewBox` or percentage-based sizes.
- **Optimized Remote Fetching**: Reads a minimal portion of remote files first, avoiding large downloads when possible.
- **Built-in Caching**: Automatically caches image dimensions to boost performance for repeated requests.
- **Laravel Native**: Seamless integration with Laravel's Filesystem, Cache, and HTTP Client.
- **Secure**: Includes basic sanitization for SVG files to prevent XSS vulnerabilities.

Requirements
------------

[](#requirements)

- PHP 8.1+
- Laravel 10.x, 11.x, or 12.x

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

[](#installation)

You can install the package via Composer:

```
composer require jackardios/laravel-image-dimensions
```

The service provider and facade will be automatically registered.

To publish the configuration file, run:

```
php artisan vendor:publish --tag="image-dimensions-config"
```

This will create a `config/image-dimensions.php` file where you can customize the package settings.

Usage
-----

[](#usage)

The package provides a simple and consistent API to get image dimensions from different sources. All methods return an associative array `['width' => int, 'height' => int]` on success or throw an exception on failure.

### Using the Facade

[](#using-the-facade)

The easiest way to use the package is through the `ImageDimensions` facade.

#### From a Local File Path

[](#from-a-local-file-path)

Provide an absolute path to a file on your server.

```
use Jackardios\ImageDimensions\Facades\ImageDimensions;

$path = public_path('images/my-image.png');

try {
    $dimensions = ImageDimensions::fromLocal($path);
    // $dimensions -> ['width' => 800, 'height' => 600]
} catch (\Exception $e) {
    // Handle exceptions like FileNotFoundException or InvalidImageException
}
```

#### From a Remote URL

[](#from-a-remote-url)

Provide a public URL to an image. Only `http` and `https` schemes are supported.

```
use Jackardios\ImageDimensions\Facades\ImageDimensions;

$url = 'https://example.com/path/to/image.jpg';

try {
    $dimensions = ImageDimensions::fromUrl($url);
    // $dimensions -> ['width' => 1920, 'height' => 1080]
} catch (\Exception $e) {
    // Handle exceptions like UrlAccessException or InvalidImageException
}
```

#### From Laravel Storage

[](#from-laravel-storage)

Provide the disk name and the path to the file within that disk. This works for both local and cloud-based storage drivers (like `s3`).

```
use Jackardios\ImageDimensions\Facades\ImageDimensions;

// Example with a local disk
$dimensions = ImageDimensions::fromStorage('public', 'uploads/avatar.png');

// Example with an S3 disk
$dimensions = ImageDimensions::fromStorage('s3', 'images/banner.svg');
```

### Exception Handling

[](#exception-handling)

The package throws specific exceptions to allow for fine-grained error handling:

- `FileNotFoundException`: The file does not exist at the specified local or storage path.
- `UrlAccessException`: The URL could not be accessed (e.g., 404 error, network timeout).
- `InvalidImageException`: The file is not a valid or supported image, or its dimensions could not be determined.
- `StorageAccessException`: The file stream or content could not be read from the storage disk.
- `TemporaryFileException`: A temporary file could not be created or written to, often due to permissions issues.

Configuration
-------------

[](#configuration)

After publishing the configuration file, you can modify the settings in `config/image-dimensions.php`.

### Caching

[](#caching)

Caching is enabled by default to improve performance.

- `enable_cache`: Set to `true` to enable caching, `false` to disable it.
- `cache_ttl`: The duration (in seconds) to cache dimensions. The default is `3600` (1 hour).

The cache key is generated based on the source type, identifier (path/URL), and file modification time (for local/storage files), ensuring the cache is automatically invalidated when a file changes.

### Remote File Handling

[](#remote-file-handling)

- `remote_read_bytes`: The number of bytes to initially read from a remote source (URL or cloud storage). This allows the package to get dimensions from the image header without downloading the entire file. Default: `131072` (128KB).
- `http`: Standard Laravel HTTP Client options like `timeout`, `connect_timeout`, and `verify_ssl`.

### SVG Handling

[](#svg-handling)

- `svg.max_file_size`: The maximum allowed file size (in bytes) for SVG files to prevent parsing of excessively large files. Default: `10485760` (10MB).

Testing
-------

[](#testing)

```
composer test
```

Contributing
------------

[](#contributing)

Contributions are welcome! Please feel free to submit a pull request for any bug fixes or improvements.

1. Fork the repository.
2. Create a new branch (`git checkout -b feature/my-new-feature`).
3. Make your changes.
4. Ensure the tests pass (`composer test`).
5. Commit your changes (`git commit -am 'Add some feature'`).
6. Push to the branch (`git push origin feature/my-new-feature`).
7. Create a new Pull Request.

License
-------

[](#license)

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

###  Health Score

33

—

LowBetter than 75% of packages

Maintenance63

Regular maintenance activity

Popularity18

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 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

228d ago

### Community

Maintainers

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

---

Top Contributors

[![Jackardios](https://avatars.githubusercontent.com/u/24757335?v=4)](https://github.com/Jackardios "Jackardios (28 commits)")

---

Tags

dimensionsimagelaravelsizestorageurlurllaravelimagestoragesizedimensions

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jackardios-laravel-image-dimensions/health.svg)

```
[![Health](https://phpackages.com/badges/jackardios-laravel-image-dimensions/health.svg)](https://phpackages.com/packages/jackardios-laravel-image-dimensions)
```

###  Alternatives

[unisharp/laravel-filemanager

A file upload/editor intended for use with Laravel 5 to 10 and CKEditor / TinyMCE

2.2k3.3M74](/packages/unisharp-laravel-filemanager)[spatie/laravel-google-cloud-storage

Google Cloud Storage filesystem driver for Laravel

2408.9M13](/packages/spatie-laravel-google-cloud-storage)[zing/laravel-flysystem-obs

Flysystem Adapter for OBS

1211.2k](/packages/zing-laravel-flysystem-obs)

PHPackages © 2026

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