{"id":22307480,"url":"https://github.com/imroychen/php-image","last_synced_at":"2025-09-05T02:18:28.886Z","repository":{"id":56993568,"uuid":"399080821","full_name":"imroychen/php-image","owner":"imroychen","description":"Simple php image processing","archived":false,"fork":false,"pushed_at":"2022-11-21T08:04:37.000Z","size":18855,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-01T05:29:47.665Z","etag":null,"topics":["crop","gd","image","image-manipulation","image-processing","imagemagick","resize","thumbnail","watermark"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/imroychen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-08-23T11:41:57.000Z","updated_at":"2022-06-17T06:29:29.000Z","dependencies_parsed_at":"2022-08-21T13:20:32.233Z","dependency_job_id":null,"html_url":"https://github.com/imroychen/php-image","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/imroychen/php-image","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imroychen%2Fphp-image","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imroychen%2Fphp-image/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imroychen%2Fphp-image/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imroychen%2Fphp-image/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/imroychen","download_url":"https://codeload.github.com/imroychen/php-image/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/imroychen%2Fphp-image/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273699926,"owners_count":25152330,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-05T02:00:09.113Z","response_time":402,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crop","gd","image","image-manipulation","image-processing","imagemagick","resize","thumbnail","watermark"],"created_at":"2024-12-03T20:10:05.121Z","updated_at":"2025-09-05T02:18:28.845Z","avatar_url":"https://github.com/imroychen.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PHP image processing and image manipulation\r\n## 示例\r\n```php\r\nuse iry\\image\\Image;\r\n$waterMark = '/img/watermark.png';\r\n//mage::setLib('Gd/ImageMagick');//可选 默认自动检测\r\n//得到对象的示例\r\n$img = Image::src('/img/test-img.jpg'); //也可以直接 new Gd('file'); 或者 new ImageMagick('file');\r\n\r\n//重置图片尺寸\r\n$img-\u003eresize(800,800);\r\n//添加水印 lt左上，rt:右上 ,l:左中，t:上中.... lt/rt/lb/rb/l/r/t/b/c | [x,y]\r\n$img-\u003ewatermark($waterMark,'c')-\u003ewatermark($waterMark,'lt',60,60)-\u003ewatermark($waterMark,'rb',120,120);\r\n//添加文本\r\n//$img-\u003eaddText('text2',14);\r\n//图片旋转90度\r\n$img-\u003erotate(90);\r\n//拉伸\r\n$img-\u003estretch(500,500,true);\r\n//保存结果\r\n$r = $img-\u003esave('{file_dir}/test.dist.jpg');\r\n//添加文字\r\n$img-\u003eaddText('left \u0026 top 左上',20,'lt','....' )\r\n    -\u003eaddText('right \u0026 bottom 右下',20,'rb',$font );\r\n\r\n//支持连贯写法\r\n//$img-\u003eresize(800,800)-\u003erotate(90)-\u003ewatermark('....')-\u003e....-\u003esave('保存');\r\n```\r\n---\r\n\r\n## 方法说明\r\n\r\n### getSize 获取图片尺寸 \r\n    静态方法\r\n    @param: 文件路径\r\n    @return: [宽,高]\r\n    \r\n### getImageInfo 获取图片信息\r\n```php\r\n    // 静态方法\r\n    Image::getImageInfo($file);\r\n    //@return \r\n    [\r\n        \"width\" =\u003e'宽',\r\n        \"height\" =\u003e'高',\r\n        \"type\" =\u003e'文件类型',\r\n        \"suf\"=\u003e'文件后缀',\r\n        \"size\" =\u003e'文件大小',\r\n        \"mime\" =\u003e'mime'\r\n    ];\r\n```\r\n\r\n### 缩放 resize\r\n```php\r\n/**\r\n * resize\r\n * @param int $width 宽\r\n * @param int $height 高\r\n * @return $this\r\n */\r\nImage::src('file')-\u003eresize(400,500);\r\n```\r\n### 裁剪图片 crop\r\n```php\r\n/**\r\n * 坐标\r\n * @param int $x x 坐标 支持\"数字\"和\"*%\"\r\n * @param int $y y 坐标 支持\"数字\"和\"*%\"\r\n * ----------\r\n * 尺寸\r\n * @param int $w WIDTH/裁剪后的宽 支持\"数字\"和\"*%\"\r\n * @param int $h HEIGHT/裁剪后的高 支持\"数字\"和\"*%\"\r\n * \r\n * @return $this\r\n */\r\nImage::src('file')-\u003ecrop(0,0,400,500);\r\n```\r\n### 旋转图片 rotate\r\n```\r\n/**\r\n * 旋转图片\r\n * @param int $angle 旋转角度\r\n * @param int $bgColor 旋转后空余背景 可选\r\n */\r\n Image::src('file')-\u003erotate(30);\r\n Image::src('file')-\u003erotate(30,'#ffffff')-\u003erotate(60);\r\n```\r\n### 添加文字(水印) addText \r\n```php\r\n/**\r\n * @param string $text 写入文字\r\n * @param $textSize GD1为像素 GD2 单位为磅（pound）\r\n * @param string|[] $position 写入文字起点坐标或者位置\r\n * 位置: lt/rt/lb/rb/t/b/l/r/c (lt leftTop 左上) (t : 上中)  坐标:[x,y]\r\n * @param $fontFile 字体文件\r\n * @param string $color\r\n * @return $this\r\n */\r\nImage::src('file.jpg')-\u003eaddText($text,12,'lt',$fontFile)\r\n```\r\n**$fontFile** 字体文件：使用绝对路径\u003cbr\u003e\r\n需要自己去\u003cu\u003e**下载**\u003c/u\u003e、也可以从的 Windows、Mac、Linux字体安装目录\u003cu\u003e**拷贝**\u003c/u\u003e字体到你的项目中\r\nwindows(C:\\Windows\\Fonts)、Mac(/System/Library/Fonts)\r\n\u003cbr\u003e**注**：部分字体可能需要商用授权（请自行联系字体发布方）\r\n\u003cbr\u003e常见字体下载:\r\n\u003cbr\u003e[Han Serif 下载地址](https://github.com/adobe-fonts/source-han-serif/tree/release/OTF)\r\n\u003cbr\u003e[Han Serif 简体中文](https://github.com/adobe-fonts/source-han-sans/tree/release/OTF/SimplifiedChinese)\r\n\r\n### 图片水印 watermark\r\n```php\r\n/**\r\n * @param string $watermarkFile\r\n * @param string $position lb/lt/rb/rt/l/r/t/b/c\r\n * l：left, r：right , t：top ,b:bottom ， c:Center\r\n * \r\n * 强制水印的大小\r\n * @param int|string $width 水印缩放至多宽？ 默认100%(水印的实际大小)\r\n * @param int|string $height 水印缩放至多高？ 默认100%(水印的实际大小)\r\n * \r\n * @return ImageMagick\r\n */\r\n\r\nImage::src('file.jpg')-\u003ewatermark('/watermark.png','rb');//位置：右下角\r\nImage::src('file.jpg')-\u003ewatermark('/watermark.png','c', 60,60); //位置：中心  水印大小，强制等比缩放到60x60\r\n```\r\n\r\n### 保存图片：save\r\n```php\r\n/**\r\n * 保存\r\n * @param string $dest 目标路径\r\n * @param bool $rmSrc 是否移除原图 可选 默认：false\r\n * @return string|false filename|false\r\n */\r\n Image::src('file')-\u003eresize(400,500)-\u003esave('test.png',true);\r\n //save 方法第一个参数 可以使用变量\r\n Image::src('file')-\u003eresize(400,500)-\u003esave('{file_dir}/test_result.{file_ext}');\r\n```\r\nsave方法第一个参数(目标文件)可以使用以下变量\r\n1. {file_dir}: 原文件所在的目录,\r\n2. {file_ext}: 原文件扩展名称,\r\n3. {file_name}: 原文件名称(不包含后缀),\r\n4. {file_full_name}: 原文件名称\r\n\r\n\r\n\r\n## 快捷方\r\n\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimroychen%2Fphp-image","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimroychen%2Fphp-image","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimroychen%2Fphp-image/lists"}