PHPackages                             mojahed/image - 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. mojahed/image

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

mojahed/image
=============

PHP wrapper for the MdsImage binary — resize, crop, effects, watermark, batch processing, and image info. Requires no GD, Imagick, or any PHP image extension.

1.0.0(1mo ago)00MITPHPPHP &gt;=7.4

Since Jun 2Pushed 1mo agoCompare

[ Source](https://github.com/md-mojahed/MdsImage-php)[ Packagist](https://packagist.org/packages/mojahed/image)[ RSS](/packages/mojahed-image/feed)WikiDiscussions master Synced 1w ago

READMEChangelogDependenciesVersions (2)Used By (0)

mojahed/image
=============

[](#mojahedimage)

PHP wrapper for the MdsImage.

Process images from PHP with zero extensions — no GD, no Imagick, no libvips.
All operations are handled by the MdsImage standalone binary. Drop the binary on any server and start processing.

---

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

[](#requirements)

- PHP &gt;= 7.4
- MdsImage binary

Install
-------

[](#install)

```
composer require mojahed/image
```

---

Setup
-----

[](#setup)

Download the MdsImage binary for your platform and place it somewhere accessible:

```
# Linux
chmod +x MdsImage-linux-amd64
sudo mv MdsImage-linux-amd64 /usr/local/bin/MdsImage

# macOS
chmod +x MdsImage-mac-arm64
sudo mv MdsImage-mac-arm64 /usr/local/bin/MdsImage
```

---

Usage
-----

[](#usage)

### Basic pattern

[](#basic-pattern)

```
use Mojahed\Image;

// Set the binary path once, reuse $image everywhere
$image = Image::setBin('/usr/local/bin/MdsImage');

// input() opens a file and returns a chainable pipeline
// output() executes and saves the result
$image->input('photo.jpg')->resize(800, 600)->output('out.jpg');
```

---

Resize
------

[](#resize)

```
// Exact resize — ignores aspect ratio
$image->input('photo.jpg')->resize(800, 600)->output('out.jpg');

// Fit within bounds — preserves aspect ratio, no crop
$image->input('photo.jpg')->fit(1200, 800)->output('out.jpg');

// Fit but never enlarge a small image
$image->input('photo.jpg')->noEnlarge()->fit(1200, 800)->output('out.jpg');

// Fill exact dimensions — crops from center
$image->input('photo.jpg')->fill(400, 400)->output('out.jpg');

// Smart thumbnail (same as fill, clearer intent)
$image->input('photo.jpg')->thumb(300, 300)->output('thumb.jpg');
```

---

Crop &amp; Canvas
-----------------

[](#crop--canvas)

```
// Crop a region: 500×400 starting at pixel (50, 30)
$image->input('photo.jpg')->crop(500, 400, 50, 30)->output('out.jpg');

// Pad canvas to exact size with a background colour
// (fit first to preserve aspect ratio, then pad to square)
$image->input('photo.jpg')
      ->fit(800, 800)
      ->pad(800, 800, '#F5F5F5')
      ->output('square.jpg');

// Add a border on all sides
$image->input('photo.jpg')->border(20, '#000000')->output('out.jpg');

// Trim uniform background from edges (default threshold = 10)
$image->input('photo.jpg')->trim()->output('trimmed.jpg');
$image->input('photo.jpg')->trim(25)->output('trimmed.jpg'); // more aggressive
```

---

Transforms
----------

[](#transforms)

```
$image->input('photo.jpg')->flip('h')->output('out.jpg');   // horizontal mirror
$image->input('photo.jpg')->flip('v')->output('out.jpg');   // upside-down
$image->input('photo.jpg')->rotate(90)->output('out.jpg');  // 90 | 180 | 270
$image->input('photo.jpg')->autoOrient()->output('out.jpg'); // fix EXIF orientation
```

---

Color &amp; Adjustments
-----------------------

[](#color--adjustments)

```
$image->input('photo.jpg')->brightness(30)->output('out.jpg');    // -100 to 100
$image->input('photo.jpg')->contrast(20)->output('out.jpg');      // -100 to 100
$image->input('photo.jpg')->saturation(40)->output('out.jpg');    // -100 to 100
$image->input('photo.jpg')->gamma(1.5)->output('out.jpg');        // positive float
$image->input('photo.jpg')->hue(120)->output('out.jpg');          // -360 to 360
$image->input('photo.jpg')->grayscale()->output('out.jpg');
$image->input('photo.jpg')->sepia()->output('out.jpg');
$image->input('photo.jpg')->invert()->output('out.jpg');
$image->input('photo.jpg')->tint('#FF6600')->output('out.jpg');
$image->input('photo.jpg')->stripExif()->output('out.jpg');
```

---

Filters
-------

[](#filters)

```
$image->input('photo.jpg')->blur(2.0)->output('out.jpg');     // Gaussian blur radius
$image->input('photo.jpg')->sharpen(1.5)->output('out.jpg');  // unsharp mask amount
```

---

Watermark
---------

[](#watermark)

```
// Positions: topleft | topright | bottomleft | bottomright | center
$image->input('photo.jpg')->watermark('logo.png')->output('out.jpg');
$image->input('photo.jpg')->watermark('logo.png', 'topleft', 60)->output('out.jpg');
```

---

Output Options
--------------

[](#output-options)

```
// JPEG quality (default 85)
$image->input('photo.jpg')->thumb(300, 300)->quality(95)->output('hq.jpg');

// Force output format
$image->input('photo.jpg')->resize(400, 400)->format('png')->output('out.png');

// Suppress binary progress output
$image->input('photo.jpg')->thumb(300, 300)->quiet()->output('out.jpg');
```

---

Output Modes
------------

[](#output-modes)

```
// Save to file
$image->input('photo.jpg')->thumb(300, 300)->output('thumb.jpg');

// Write to stdout (for streaming HTTP responses)
$image->input('photo.jpg')->thumb(300, 300)->output('-');

// Raw base64 string
$b64 = $image->input('photo.jpg')->thumb(300, 300)->toBase64();

// data: URI — ready for , CSS, or JSON API payloads
$uri = $image->input('photo.jpg')->thumb(300, 300)->toDataUri();
echo '';
```

---

Image Info
----------

[](#image-info)

```
// Get all metadata as an associative array
$info = $image->input('photo.jpg')->info();

echo $info['width'];                    // 1024
echo $info['height'];                   // 768
echo $info['format'];                   // JPEG
echo $info['mime_type'];                // image/jpeg
echo $info['file_size_human'];          // 1.2 MB
echo $info['megapixels'];               // 0.79
echo $info['aspect_ratio'];             // 4:3
echo $info['color_mode'];               // RGB
echo $info['has_alpha'];                // false
echo $info['average_color']['hex'];     // C0BCAB

foreach ($info['dominant_colors'] as $c) {
    echo "#{$c['hex']}  rgb({$c['r']},{$c['g']},{$c['b']})\n";
}

// JPEG-specific (present only for JPEG files)
if (!empty($info['jpeg'])) {
    echo $info['jpeg']['exif_make'];         // Apple
    echo $info['jpeg']['exif_model'];        // iPhone 15 Pro
    echo $info['jpeg']['exif_datetime'];     // 2024:03:15 14:22:00
    echo $info['jpeg']['exif_iso'];          // 100
    echo $info['jpeg']['exif_fnumber'];      // 1.8
    echo $info['jpeg']['exif_exposure_time']; // 1/1000 s
    echo $info['jpeg']['exif_focal_length_mm']; // 24
    if ($info['jpeg']['exif_gps_present']) {
        echo $info['jpeg']['exif_gps_lat'] . ', ' . $info['jpeg']['exif_gps_lon'];
    }
}

// PNG-specific (present only for PNG files)
if (!empty($info['png'])) {
    echo $info['png']['color_type'];         // RGBA
    echo $info['png']['interlaced'];         // false
    // text_chunks: author, description, copyright, etc.
}

// Get info as a JSON string
$json = $image->input('photo.jpg')->infoJson();
```

---

Chained Pipelines
-----------------

[](#chained-pipelines)

Operations are applied in the exact order you call them:

```
// Full production pipeline
$image->input('raw-upload.jpg')
      ->autoOrient()
      ->noEnlarge()->fit(1920, 1080)
      ->brightness(5)
      ->contrast(10)
      ->saturation(15)
      ->sharpen(0.8)
      ->watermark('brand.png', 'bottomright', 75)
      ->stripExif()
      ->quality(92)
      ->output('final.jpg');

// Thumbnail with sepia effect
$image->input('photo.jpg')
      ->thumb(300, 300)
      ->sepia()
      ->output('thumb-sepia.jpg');

// E-commerce product image (exact square, no crop, no distortion)
$image->input('product.jpg')
      ->trim()
      ->noEnlarge()->fit(800, 800)
      ->pad(800, 800, '#FFFFFF')
      ->sharpen(0.5)
      ->quality(90)
      ->output('product-800.jpg');
```

---

Batch Processing
----------------

[](#batch-processing)

Process multiple files concurrently with worker parallelism:

```
// All JPEGs in a folder → thumbnails
$results = $image->batch()
    ->glob('photos/*.jpg')
    ->outDir('thumbs/')
    ->thumb(300, 300)
    ->quality(85)
    ->run();

// Process all images in a directory with a custom filename pattern
$results = $image->batch()
    ->dir('uploads/')
    ->outDir('processed/')
    ->pattern('{name}-800w{ext}')    // {name}, {ext}, {base} tokens
    ->noEnlarge()->fit(800, 600)
    ->sharpen(1.0)
    ->quality(88)
    ->workers(4)
    ->run();

// Convert folder to PNG
$results = $image->batch()
    ->glob('assets/*.jpg')
    ->outDir('assets/png/')
    ->format('png')
    ->run();

// Check results
foreach ($results as $r) {
    if ($r['error'] !== null) {
        echo "✗ {$r['input']}: {$r['error']}\n";
    } else {
        echo "✓ {$r['input']} → {$r['output']}\n";
    }
}
```

### Batch methods

[](#batch-methods)

MethodDescription`->glob('photos/*.jpg')`Input files matching a glob pattern`->dir('uploads/')`All images in a directory`->outDir('thumbs/')`Output directory (required)`->pattern('{name}-sm{ext}')`Output filename pattern`->format('png')`Force output format`->quality(85)`JPEG quality`->workers(4)`Parallel workers (default: CPU count, max 8)`->quiet()`Suppress progress outputAll image operations (`resize`, `thumb`, `sepia`, `watermark`, etc.) are available on `BatchBuilder` too.

---

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

[](#error-handling)

```
try {
    $image->input('missing.jpg')->resize(800, 600)->output('out.jpg');
} catch (\RuntimeException $e) {
    echo $e->getMessage();
    // "MdsImage failed (exit 1): input file not found: missing.jpg"
}
```

Exit code `1` = processing or IO error.
Exit code `2` = usage error (won't occur from the PHP wrapper under normal use).

---

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

[](#supported-formats)

DirectionFormatsInputJPEG, PNG, GIF, BMP, TIFF, WebPOutputJPEG, PNG---

License
-------

[](#license)

MIT © Md Mojahedul Islam

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance90

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community2

Small or concentrated contributor base

Maturity33

Early-stage or recently created project

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

52d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/92214734?v=4)[Md Mojahedul Islam](/maintainers/md-mojahed)[@md-mojahed](https://github.com/md-mojahed)

---

Tags

thumbnailimagebase64image processingresizewatermarkbatchcropexifgdless

### Embed Badge

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

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

###  Alternatives

[intervention/image

PHP Image Processing

14.4k208.9M2.6k](/packages/intervention-image)[sybio/image-workshop

Powerful PHP class using GD library to work easily with images including layer notion (like Photoshop or GIMP)

854945.6k12](/packages/sybio-image-workshop)[intervention/image-laravel

Laravel Integration of Intervention Image

1588.9M201](/packages/intervention-image-laravel)[jbzoo/image

A PHP class that simplifies working with images

174129.4k3](/packages/jbzoo-image)[stefangabos/zebra_image

A single-file, lightweight PHP library designed for efficient image manipulation featuring methods for modifying images and applying filters

138118.5k7](/packages/stefangabos-zebra-image)[coldume/imagecraft

A reliable and extensible PHP image manipulation library

10034.1k2](/packages/coldume-imagecraft)

PHPackages © 2026

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