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

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

iry/image
=========

php image process. PHP图片快捷处理

v1.0.2(3y ago)049MITPHPPHP &gt;=5.4

Since Aug 23Pushed 3y ago1 watchersCompare

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

READMEChangelogDependenciesVersions (4)Used By (0)

PHP image processing and image manipulation
===========================================

[](#php-image-processing-and-image-manipulation)

示例
--

[](#示例)

```
use iry\image\Image;
$waterMark = '/img/watermark.png';
//mage::setLib('Gd/ImageMagick');//可选 默认自动检测
//得到对象的示例
$img = Image::src('/img/test-img.jpg'); //也可以直接 new Gd('file'); 或者 new ImageMagick('file');

//重置图片尺寸
$img->resize(800,800);
//添加水印 lt左上，rt:右上 ,l:左中，t:上中.... lt/rt/lb/rb/l/r/t/b/c | [x,y]
$img->watermark($waterMark,'c')->watermark($waterMark,'lt',60,60)->watermark($waterMark,'rb',120,120);
//添加文本
//$img->addText('text2',14);
//图片旋转90度
$img->rotate(90);
//拉伸
$img->stretch(500,500,true);
//保存结果
$r = $img->save('{file_dir}/test.dist.jpg');
//添加文字
$img->addText('left & top 左上',20,'lt','....' )
    ->addText('right & bottom 右下',20,'rb',$font );

//支持连贯写法
//$img->resize(800,800)->rotate(90)->watermark('....')->....->save('保存');
```

---

方法说明
----

[](#方法说明)

### getSize 获取图片尺寸

[](#getsize-获取图片尺寸)

```
静态方法
@param: 文件路径
@return: [宽,高]

```

### getImageInfo 获取图片信息

[](#getimageinfo-获取图片信息)

```
    // 静态方法
    Image::getImageInfo($file);
    //@return
    [
        "width" =>'宽',
        "height" =>'高',
        "type" =>'文件类型',
        "suf"=>'文件后缀',
        "size" =>'文件大小',
        "mime" =>'mime'
    ];
```

### 缩放 resize

[](#缩放-resize)

```
/**
 * resize
 * @param int $width 宽
 * @param int $height 高
 * @return $this
 */
Image::src('file')->resize(400,500);
```

### 裁剪图片 crop

[](#裁剪图片-crop)

```
/**
 * 坐标
 * @param int $x x 坐标 支持"数字"和"*%"
 * @param int $y y 坐标 支持"数字"和"*%"
 * ----------
 * 尺寸
 * @param int $w WIDTH/裁剪后的宽 支持"数字"和"*%"
 * @param int $h HEIGHT/裁剪后的高 支持"数字"和"*%"
 *
 * @return $this
 */
Image::src('file')->crop(0,0,400,500);
```

### 旋转图片 rotate

[](#旋转图片-rotate)

```
/**
 * 旋转图片
 * @param int $angle 旋转角度
 * @param int $bgColor 旋转后空余背景 可选
 */
 Image::src('file')->rotate(30);
 Image::src('file')->rotate(30,'#ffffff')->rotate(60);

```

### 添加文字(水印) addText

[](#添加文字水印-addtext)

```
/**
 * @param string $text 写入文字
 * @param $textSize GD1为像素 GD2 单位为磅（pound）
 * @param string|[] $position 写入文字起点坐标或者位置
 * 位置: lt/rt/lb/rb/t/b/l/r/c (lt leftTop 左上) (t : 上中)  坐标:[x,y]
 * @param $fontFile 字体文件
 * @param string $color
 * @return $this
 */
Image::src('file.jpg')->addText($text,12,'lt',$fontFile)
```

**$fontFile** 字体文件：使用绝对路径
需要自己去**下载**、也可以从的 Windows、Mac、Linux字体安装目录**拷贝**字体到你的项目中 windows(C:\\Windows\\Fonts)、Mac(/System/Library/Fonts)
**注**：部分字体可能需要商用授权（请自行联系字体发布方）
常见字体下载:
[Han Serif 下载地址](https://github.com/adobe-fonts/source-han-serif/tree/release/OTF)
[Han Serif 简体中文](https://github.com/adobe-fonts/source-han-sans/tree/release/OTF/SimplifiedChinese)

### 图片水印 watermark

[](#图片水印-watermark)

```
/**
 * @param string $watermarkFile
 * @param string $position lb/lt/rb/rt/l/r/t/b/c
 * l：left, r：right , t：top ,b:bottom ， c:Center
 *
 * 强制水印的大小
 * @param int|string $width 水印缩放至多宽？ 默认100%(水印的实际大小)
 * @param int|string $height 水印缩放至多高？ 默认100%(水印的实际大小)
 *
 * @return ImageMagick
 */

Image::src('file.jpg')->watermark('/watermark.png','rb');//位置：右下角
Image::src('file.jpg')->watermark('/watermark.png','c', 60,60); //位置：中心  水印大小，强制等比缩放到60x60
```

### 保存图片：save

[](#保存图片save)

```
/**
 * 保存
 * @param string $dest 目标路径
 * @param bool $rmSrc 是否移除原图 可选 默认：false
 * @return string|false filename|false
 */
 Image::src('file')->resize(400,500)->save('test.png',true);
 //save 方法第一个参数 可以使用变量
 Image::src('file')->resize(400,500)->save('{file_dir}/test_result.{file_ext}');
```

save方法第一个参数(目标文件)可以使用以下变量

1. {file\_dir}: 原文件所在的目录,
2. {file\_ext}: 原文件扩展名称,
3. {file\_name}: 原文件名称(不包含后缀),
4. {file\_full\_name}: 原文件名称

快捷方
---

[](#快捷方)

###  Health Score

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity48

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

Total

3

Last Release

1431d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/332367a6e49c4e91e2b816a39fdcecf212415f826cf0261981bc1db95075f6e2?d=identicon)[roychen](/maintainers/roychen)

---

Top Contributors

[![roy2chen](https://avatars.githubusercontent.com/u/4337618?v=4)](https://github.com/roy2chen "roy2chen (13 commits)")

---

Tags

cropgdimageimage-manipulationimage-processingimagemagickresizethumbnailwatermarkthumbnailimageImageMagickgdimagickresizewatermarkcropphp image processing

### Embed Badge

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

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

###  Alternatives

[intervention/image

PHP Image Processing

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

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

860918.1k11](/packages/sybio-image-workshop)[intervention/image-laravel

Laravel Integration of Intervention Image

1496.5M102](/packages/intervention-image-laravel)[jbzoo/image

A PHP class that simplifies working with images

171126.9k3](/packages/jbzoo-image)[folklore/image

Image manipulation library for Laravel 5 based on Imagine and inspired by Croppa for easy url based manipulation

270248.2k5](/packages/folklore-image)[stefangabos/zebra_image

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

141110.4k6](/packages/stefangabos-zebra-image)

PHPackages © 2026

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