PHPackages                             iglesias/image-converter - 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. [Image &amp; Media](/categories/media)
4. /
5. iglesias/image-converter

ActiveLibrary[Image &amp; Media](/categories/media)

iglesias/image-converter
========================

PHP Image Converter with GD

0.1.2(7mo ago)011MITPHPPHP &gt;=7.4

Since Aug 11Pushed 7mo agoCompare

[ Source](https://github.com/igoiglesias/ImageConverter)[ Packagist](https://packagist.org/packages/iglesias/image-converter)[ RSS](/packages/iglesias-image-converter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)DependenciesVersions (3)Used By (0)

ImageConverter PHP Library
==========================

[](#imageconverter-php-library)

A lightweight, efficient PHP class for converting images between formats using the GD extension. It supports dynamic detection of GD capabilities, resizing, quality adjustment, and output to disk or Base64-encoded strings. Ideal for web applications needing on-the-fly image optimization, like reducing file sizes for faster loading without external dependencies.

This library prioritizes performance by leveraging GD's native functions and avoiding unnecessary overhead. It's designed for production use but can be optimized further for high-volume scenarios.

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

[](#requirements)

- PHP 7.4+ (compatible with 8.x)
- GD extension enabled (compile with `--with-gd` or install via package manager like `apt install php-gd`)
- Memory limit: At least 128MB recommended for large images; GD can be memory-hungry during resizing.

Verify GD support: Run `php -i | grep GD` or use `ImageConverter::getTypesSupported()` in your code.

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

[](#installation)

1. Clone the repo: `git clone https://github.com/yourusername/imageconverter.git`
2. Include the class in your project: `require_once 'ImageConverter.php';`
3. Using Composer: composer `require iglesias/image-converter`

Usage
-----

[](#usage)

### Convert to Disk

[](#convert-to-disk)

Save an image to a new file in the desired format, with optional quality and resize.

```
ImageConverter::convertToDisk('input.jpg', 'output.webp', 'webp', 80, 800, 600);
```

- Parameters:
    - `$file_path`: Path to source image (string, required).
    - `$save_path`: Path to save converted image (string, required).
    - `$format`: Target format (string, default 'webp'; e.g., 'png', 'jpeg').
    - `$quality`: Compression level (int, 0-100, default 80; lower = smaller file, more lossy).
    - `$width`: New width in pixels (int, default 0 = no resize).
    - `$height`: New height in pixels (int, default 0 = no resize).

### Convert to Base64

[](#convert-to-base64)

Generate a Base64 string for inline use (e.g., in HTML ``).

```
$base64 = ImageConverter::convertToBase64('input.jpg', 'webp', 80, 800, 600);
echo '';
```

- Parameters: Same as `convertToDisk`, minus `$save_path`.
- Returns: `data:image/format;base64,...` string.

### Get Supported Formats

[](#get-supported-formats)

Dynamically list formats GD supports on your system.

```
print_r(ImageConverter::getTypesSupported()); // e.g., ['image/jpeg', 'image/png', 'image/webp']
```

Supported Formats
-----------------

[](#supported-formats)

Depends on your GD build. Common ones: JPEG, PNG, GIF, WebP, BMP, AVIF. The class auto-detects via `gd_info()` and filters to: `image/jpeg`, `image/png`, `image/gif`, `image/webp`, `image/bmp`, `image/avif`.

Quality scales differently:

- JPEG/WebP/AVIF: 0-100
- PNG: 0-9 (compression level)
- GIF/BMP: No quality param (lossless)

Error Handling
--------------

[](#error-handling)

Methods throw `Exception` on issues like:

- GD not loaded
- Unsupported format/file type
- File not found/invalid
- Image creation failure

Wrap calls in try-catch for robustness:

```
try {
    ImageConverter::convertToDisk(...);
} catch (Exception $e) {
    echo "Error: " . $e->getMessage();
}
```

License
-------

[](#license)

MIT License. See LICENSE file.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance64

Regular maintenance activity

Popularity5

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity27

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

Every ~50 days

Total

2

Last Release

222d ago

### Community

Maintainers

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

---

Top Contributors

[![igoiglesias](https://avatars.githubusercontent.com/u/2658126?v=4)](https://github.com/igoiglesias "igoiglesias (7 commits)")

### Embed Badge

![Health badge](/badges/iglesias-image-converter/health.svg)

```
[![Health](https://phpackages.com/badges/iglesias-image-converter/health.svg)](https://phpackages.com/packages/iglesias-image-converter)
```

###  Alternatives

[milon/barcode

Barcode generator like Qr Code, PDF417, C39, C39+, C39E, C39E+, C93, S25, S25+, I25, I25+, C128, C128A, C128B, C128C, 2-Digits UPC-Based Extention, 5-Digits UPC-Based Extention, EAN 8, EAN 13, UPC-A, UPC-E, MSI (Variation of Plessey code)

1.5k13.3M39](/packages/milon-barcode)[bkwld/croppa

Image thumbnail creation through specially formatted URLs for Laravel

510496.0k23](/packages/bkwld-croppa)[goat1000/svggraph

Generates SVG graphs

132849.6k3](/packages/goat1000-svggraph)[cohensive/embed

Media Embed (for Laravel or as a standalone).

120370.4k](/packages/cohensive-embed)[netresearch/rte-ckeditor-image

Image support in CKEditor for the TYPO3 ecosystem - by Netresearch

63991.3k4](/packages/netresearch-rte-ckeditor-image)[humanmade/tachyon-plugin

Rewrites WordPress image URLs to use Tachyon

87338.5k2](/packages/humanmade-tachyon-plugin)

PHPackages © 2026

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