PHPackages                             kiatng/php-sharp - 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. kiatng/php-sharp

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

kiatng/php-sharp
================

A PHP wrapper for sharp js

v0.0.2(4mo ago)27MITPHPPHP &gt;=7.4

Since Nov 7Pushed 4mo ago1 watchersCompare

[ Source](https://github.com/kiatng/php-sharp)[ Packagist](https://packagist.org/packages/kiatng/php-sharp)[ RSS](/packages/kiatng-php-sharp/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

PHP Sharp
=========

[](#php-sharp)

A PHP wrapper for [lovell/sharp](https://github.com/lovell/sharp), a high performance Node.js image processing library.

Common use cases:

- Resize image
- Convert image format

For more information on Sharp, see the official documentation [here](https://sharp.pixelplumbing.com/).

Prerequisites
-------------

[](#prerequisites)

Install [node](https://nodejs.org/) in your system. Installation of node is very simple.

Check if you have node installed:

```
node -v
```

The command should display the version number.

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

[](#installation)

Install the packages at the root of your PHP project:

```
composer require kiatng/php-sharp
npm install sharp
```

This last command will create a `node_modules` directory, `package-lock.json` and `package.json`.

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

[](#requirements)

- PHP &gt;= 7.4
- Node.js and npm (for Sharp installation)
- Sharp npm package

Usage
-----

[](#usage)

There is only one static method `run` in the `Sharp` class. It takes three arguments:

- `$io`: Input and output parameters
- `$params`: Parameters for the image processing
- `$constructorOptions` (optional): Sharp constructor options (e.g., `density`, `failOn`, `limitInputPixels`)

Refer to the [Sharp documentation](https://sharp.pixelplumbing.com/) on the specifications of the parameters.

### Examples

[](#examples)

Convert SVG to PNG and resize the image:

```
use KiatNg\Sharp;

$png = Sharp::run(
    [
        'input' => ['is_raw' => true, 'data' => $svg, 'ext' => 'svg'],
        'output' => ['is_raw' => true],
    ],
    [
        'toFormat' => ['format' => 'png'], // Required for raw output
        'resize' => ['width' => 300, 'height' => 200]
    ]
); // Returns a raw PNG binary string
```

`is_raw` is a boolean parameter that indicates if the input is a raw data or a file path. `$svg` is the raw SVG XML string. `ext` is the image format: jpg, png, svg of the source data; it's used as the file extension internally.

Example with file paths including filename and extension:

```
Sharp::run(
    [
        'input' => ['is_raw' => false, 'data' => $svgPath],
        'output' => ['is_raw' => false, 'file' => $pngPath],
    ],
    [
        //'toFormat' => ['format' => 'png'], Not required if $pngPath has .png extension
        'resize' => ['width' => 300, 'height' => 200]
    ]
);
```

Example with constructor options (e.g., setting DPI for SVG rendering):

```
Sharp::run(
    [
        'input' => ['is_raw' => false, 'data' => $svgPath],
        'output' => ['is_raw' => false, 'file' => $pngPath],
    ],
    [
        'resize' => ['width' => 300, 'height' => 200]
    ],
    ['density' => 300] // Set DPI to 300 for higher quality SVG rendering
);
```

Refer to the test cases in `tests/Unit/SharpTest.php` for more examples.

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

[](#contributing)

Contributions are welcome! Here's how you can help:

1. Fork the repository
2. Create your feature branch (`git checkout -b feature/amazing-feature`)
3. Install dependencies:

```
composer install
npm install
```

4. Make your changes and add your feature
5. Write or update tests for your changes if applicable
6. Run tests to ensure everything works:

```
composer test
```

7. Commit your changes (`git commit -m 'Add some amazing feature'`)
8. Push to the branch (`git push origin feature/amazing-feature`)
9. Open a Pull Request

### Contributors ✨

[](#contributors-)

Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):

This project follows the [all-contributors](https://github.com/all-contributors/all-contributors) specification. Contributions of any kind welcome!

### Code Style

[](#code-style)

- Follow PSR-12 coding standards
- Add tests for new features
- Update documentation as needed

License
-------

[](#license)

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.

Acknowledgement
---------------

[](#acknowledgement)

This project was inspired by [choowx/rasterize-svg](https://github.com/choowx/rasterize-svg).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance77

Regular maintenance activity

Popularity7

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 77.8% 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 ~429 days

Total

2

Last Release

127d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/751e8482cfb43e560a8b7bf561d7db5f47661932061d9603324afe957b4b9e3f?d=identicon)[kiatng](/maintainers/kiatng)

---

Top Contributors

[![kiatng](https://avatars.githubusercontent.com/u/1106470?v=4)](https://github.com/kiatng "kiatng (7 commits)")[![Copilot](https://avatars.githubusercontent.com/in/1143301?v=4)](https://github.com/Copilot "Copilot (2 commits)")

---

Tags

imageprocessingresizeoptimizesharp

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kiatng-php-sharp/health.svg)

```
[![Health](https://phpackages.com/badges/kiatng-php-sharp/health.svg)](https://phpackages.com/packages/kiatng-php-sharp)
```

###  Alternatives

[intervention/image

PHP Image Processing

14.3k194.3M2.2k](/packages/intervention-image)[league/glide

Wonderfully easy on-demand image manipulation library with an HTTP based API.

2.6k51.2M116](/packages/league-glide)[spatie/image

Manipulate images with an expressive API

1.4k54.4M138](/packages/spatie-image)[gumlet/php-image-resize

PHP class to re-size and scale images

1.2k5.7M54](/packages/gumlet-php-image-resize)[jcupitt/vips

A high-level interface to the libvips image processing library.

6961.6M31](/packages/jcupitt-vips)[masterexploder/phpthumb

A library for manipulating images in PHP.

981751.7k17](/packages/masterexploder-phpthumb)

PHPackages © 2026

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