{"id":28927956,"url":"https://github.com/jackardios/laravel-image-dimensions","last_synced_at":"2026-01-20T16:34:06.198Z","repository":{"id":299876848,"uuid":"1004505147","full_name":"Jackardios/laravel-image-dimensions","owner":"Jackardios","description":"A Laravel package to efficiently determine image dimensions from local files, URLs, and Laravel storage.","archived":false,"fork":false,"pushed_at":"2025-06-18T19:25:15.000Z","size":43,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-06-18T19:38:20.526Z","etag":null,"topics":["dimensions","image","laravel","size","storage","url"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jackardios.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-06-18T18:19:27.000Z","updated_at":"2025-06-18T19:25:18.000Z","dependencies_parsed_at":"2025-06-18T19:39:05.553Z","dependency_job_id":"1082ac18-0445-43f1-989d-f74144c05186","html_url":"https://github.com/Jackardios/laravel-image-dimensions","commit_stats":null,"previous_names":["jackardios/laravel-image-dimensions"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Jackardios/laravel-image-dimensions","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jackardios%2Flaravel-image-dimensions","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jackardios%2Flaravel-image-dimensions/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jackardios%2Flaravel-image-dimensions/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jackardios%2Flaravel-image-dimensions/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jackardios","download_url":"https://codeload.github.com/Jackardios/laravel-image-dimensions/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jackardios%2Flaravel-image-dimensions/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261304265,"owners_count":23138301,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dimensions","image","laravel","size","storage","url"],"created_at":"2025-06-22T14:11:26.324Z","updated_at":"2026-01-20T16:34:06.191Z","avatar_url":"https://github.com/Jackardios.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Image Dimensions\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/jackardios/laravel-image-dimensions.svg?style=flat-square)](https://packagist.org/packages/jackardios/laravel-image-dimensions)\n[![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)\n\nA 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.\n\n### Features\n\n-   **Multiple Sources**: Get dimensions from local file paths, remote URLs, and Laravel Storage disks.\n-   **Wide Format Support**: Supports common image formats like PNG, JPEG, GIF, WebP, and BMP.\n-   **Advanced SVG Parsing**: Correctly determines dimensions from SVGs, including those using `viewBox` or percentage-based sizes.\n-   **Optimized Remote Fetching**: Reads a minimal portion of remote files first, avoiding large downloads when possible.\n-   **Built-in Caching**: Automatically caches image dimensions to boost performance for repeated requests.\n-   **Laravel Native**: Seamless integration with Laravel's Filesystem, Cache, and HTTP Client.\n-   **Secure**: Includes basic sanitization for SVG files to prevent XSS vulnerabilities.\n\n## Requirements\n\n-   PHP 8.1+\n-   Laravel 10.x, 11.x, or 12.x\n\n## Installation\n\nYou can install the package via Composer:\n\n```bash\ncomposer require jackardios/laravel-image-dimensions\n```\n\nThe service provider and facade will be automatically registered.\n\nTo publish the configuration file, run:\n\n```bash\nphp artisan vendor:publish --tag=\"image-dimensions-config\"\n```\n\nThis will create a `config/image-dimensions.php` file where you can customize the package settings.\n\n## Usage\n\nThe package provides a simple and consistent API to get image dimensions from different sources. All methods return an associative array `['width' =\u003e int, 'height' =\u003e int]` on success or throw an exception on failure.\n\n### Using the Facade\n\nThe easiest way to use the package is through the `ImageDimensions` facade.\n\n#### From a Local File Path\n\nProvide an absolute path to a file on your server.\n\n```php\nuse Jackardios\\ImageDimensions\\Facades\\ImageDimensions;\n\n$path = public_path('images/my-image.png');\n\ntry {\n    $dimensions = ImageDimensions::fromLocal($path);\n    // $dimensions -\u003e ['width' =\u003e 800, 'height' =\u003e 600]\n} catch (\\Exception $e) {\n    // Handle exceptions like FileNotFoundException or InvalidImageException\n}\n```\n\n#### From a Remote URL\n\nProvide a public URL to an image. Only `http` and `https` schemes are supported.\n\n```php\nuse Jackardios\\ImageDimensions\\Facades\\ImageDimensions;\n\n$url = 'https://example.com/path/to/image.jpg';\n\ntry {\n    $dimensions = ImageDimensions::fromUrl($url);\n    // $dimensions -\u003e ['width' =\u003e 1920, 'height' =\u003e 1080]\n} catch (\\Exception $e) {\n    // Handle exceptions like UrlAccessException or InvalidImageException\n}\n```\n\n#### From Laravel Storage\n\nProvide the disk name and the path to the file within that disk. This works for both local and cloud-based storage drivers (like `s3`).\n\n```php\nuse Jackardios\\ImageDimensions\\Facades\\ImageDimensions;\n\n// Example with a local disk\n$dimensions = ImageDimensions::fromStorage('public', 'uploads/avatar.png');\n\n// Example with an S3 disk\n$dimensions = ImageDimensions::fromStorage('s3', 'images/banner.svg');\n```\n\n### Exception Handling\n\nThe package throws specific exceptions to allow for fine-grained error handling:\n\n-   `FileNotFoundException`: The file does not exist at the specified local or storage path.\n-   `UrlAccessException`: The URL could not be accessed (e.g., 404 error, network timeout).\n-   `InvalidImageException`: The file is not a valid or supported image, or its dimensions could not be determined.\n-   `StorageAccessException`: The file stream or content could not be read from the storage disk.\n-   `TemporaryFileException`: A temporary file could not be created or written to, often due to permissions issues.\n\n## Configuration\n\nAfter publishing the configuration file, you can modify the settings in `config/image-dimensions.php`.\n\n### Caching\n\nCaching is enabled by default to improve performance.\n\n-   `enable_cache`: Set to `true` to enable caching, `false` to disable it.\n-   `cache_ttl`: The duration (in seconds) to cache dimensions. The default is `3600` (1 hour).\n\nThe 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.\n\n### Remote File Handling\n\n-   `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).\n-   `http`: Standard Laravel HTTP Client options like `timeout`, `connect_timeout`, and `verify_ssl`.\n\n### SVG Handling\n\n-   `svg.max_file_size`: The maximum allowed file size (in bytes) for SVG files to prevent parsing of excessively large files. Default: `10485760` (10MB).\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Contributing\n\nContributions are welcome! Please feel free to submit a pull request for any bug fixes or improvements.\n\n1.  Fork the repository.\n2.  Create a new branch (`git checkout -b feature/my-new-feature`).\n3.  Make your changes.\n4.  Ensure the tests pass (`composer test`).\n5.  Commit your changes (`git commit -am 'Add some feature'`).\n6.  Push to the branch (`git push origin feature/my-new-feature`).\n7.  Create a new Pull Request.\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackardios%2Flaravel-image-dimensions","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjackardios%2Flaravel-image-dimensions","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjackardios%2Flaravel-image-dimensions/lists"}