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

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

trisnawan/image-resizer
=======================

Resizer, Thumbnailer, Cropper Image with PHP Imagick

v2.0.0(1mo ago)182MITPHPPHP &gt;=7.4.0

Since Jan 29Pushed 1mo ago1 watchersCompare

[ Source](https://github.com/trisnawan/image-resizer)[ Packagist](https://packagist.org/packages/trisnawan/image-resizer)[ RSS](/packages/trisnawan-image-resizer/feed)WikiDiscussions master Synced 2w ago

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

Image Resizer
=============

[](#image-resizer)

Resize, crop, convert, and watermark images using either Imagick or GD with the same API.

Instalation
-----------

[](#instalation)

```
composer require trisnawan/image-resizer
```

Initialization
--------------

[](#initialization)

```
use Trisnawan\ImageResizer\ImageResizer;
```

```
// Image from user upload
$filePath = $_FILES["image"]["tmp_name"];

// Image from local storage
$filePath = "path/to/image_file.jpg";

// Default library: Imagick
$resizer = new ImageResizer($filePath);

// Explicit Imagick
$resizer = new ImageResizer($filePath, 'imagick');

// Use GD
$resizer = new ImageResizer($filePath, 'gd');

// Optional PDF render resolution in DPI
$resizer = new ImageResizer($filePath, 'imagick', 300);
```

PDF Source
----------

[](#pdf-source)

```
// Automatically load the first page of a PDF
$resizer = new ImageResizer('../folder/file.pdf');

// Load page 2 from a PDF
$resizer = new ImageResizer('../folder/file.pdf[2]');

// Render a PDF page with higher resolution for sharper output
$resizer = new ImageResizer('../folder/file.pdf[2]', 'imagick', 300);

// If GD is selected for a PDF, the library automatically falls back to Imagick
$resizer = new ImageResizer('../folder/file.pdf', 'gd', 300);
```

`$pdfResolution` is optional and only affects PDF sources. The default value is `150` DPI. PDF page numbers in the path use one-based numbering, so `[1]` is the first page and `[2]` is the second page.

Resize Image
------------

[](#resize-image)

Use the maximum pixels and the image will be automatically reduced to the maximum size.

```
// Max Width in pixels
$maxWidth = 640;
$resizer->maxWidth($maxWidth);
```

Crop Image
----------

[](#crop-image)

```
// Crop the image into a square from the center
$resizer->cropCenter();

// Crop the image into a square from the top
$resizer->cropTop();
```

Add Text Watermark
------------------

[](#add-text-watermark)

```
// Basic watermark with automatic bottom-right placement
$resizer->createWatermark('© My Brand');

// Manual position
$resizer->createWatermark('© My Brand', 20, 40);

// Manual position with custom size, opacity, and color
$resizer->createWatermark('© My Brand', 20, 40, 24, 0.45, '#ffffff');

// Opacity also accepts percent values
$resizer->createWatermark('© My Brand', null, null, 18, 55, '#f5f5f5');
```

Parameter summary:

- `$text`: watermark text.
- `$x`: horizontal position. If omitted, the watermark is placed automatically at the bottom-right.
- `$y`: vertical position. If omitted, the watermark is placed automatically at the bottom-right.
- `$size`: optional text size.
- `$opacity`: optional opacity, accepts `0..1` or `1..100`.
- `$color`: optional hex color such as `#ffffff` or `#fff`.

GD uses TrueType text automatically when a common system font is available, and falls back to the built-in GD bitmap font otherwise.

Save to Local Storage
---------------------

[](#save-to-local-storage)

```
// Keep the original format if the extension is the same
$saveFilePath = "path/to/image_new.jpg";
$resizer->writeImage($saveFilePath);

// Convert output format based on the target extension
$resizer->writeImage('path/to/image_new.webp');
$resizer->writeImage('path/to/image_new.png');
```

If the output filename has no extension, the original image format is used.

Show Blob Image
---------------

[](#show-blob-image)

```
// Show in blob
$blob = $resizer->getBlob();
```

Full Example
------------

[](#full-example)

```
use Trisnawan\ImageResizer\ImageResizer;

$filePath = $_FILES["image"]["tmp_name"];

$resizer = new ImageResizer($filePath, 'gd');
$resizer->maxWidth(1280);
$resizer->cropCenter();
$resizer->createWatermark('© My Brand', null, null, 20, 0.5, '#ffffff');
$resizer->writeImage('uploads/profile.webp');
```

###  Health Score

42

—

FairBetter than 88% of packages

Maintenance93

Actively maintained with recent releases

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity45

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 ~448 days

Total

3

Last Release

36d ago

Major Versions

v1.1.0 → v2.0.02026-07-13

### Community

Maintainers

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

---

Top Contributors

[![trisnawan](https://avatars.githubusercontent.com/u/64518006?v=4)](https://github.com/trisnawan "trisnawan (6 commits)")

---

Tags

thumbnailresizecrop

### Embed Badge

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

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

###  Alternatives

[intervention/image

PHP Image Processing

14.4k214.2M2.8k](/packages/intervention-image)[sybio/image-workshop

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

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

Laravel Integration of Intervention Image

1589.8M226](/packages/intervention-image-laravel)[jbzoo/image

A PHP class that simplifies working with images

171130.3k3](/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

138121.6k7](/packages/stefangabos-zebra-image)[ctessier/nova-advanced-image-field

An advanced image field for Nova with cropping and resizing.

102574.4k1](/packages/ctessier-nova-advanced-image-field)

PHPackages © 2026

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