pluritech-image-php / image-php
此软件包旨在上传图像(目前仅支持gif、jpg和png格式)并自动根据预配置的配置进行缩放。
1.1.0
2018-06-14 14:06 UTC
Requires
- php: >=5.3.3
- ext-gd: *
README
从Base 64上传PHP图像(v1)
此存储库包含开源PHP代码,允许您使用预配置的尺寸从PHP应用程序上传图像。
安装
可以使用 Composer 安装此库。运行以下命令
composer require pluritech-image-php/image-php
用法
简单使用示例。
require_once __DIR__ . '/vendor/autoload.php'; // change path as needed use ImagePhp\GeneratorImageSDK as GeneratorImageSDK; use \Exception; use ImagePhp\Exception\ImageException; $url_path = //web path where the picture will be uploaded $dir = //path where the picture will be uploaded $config['url'] = $url_path; $config['dir'] = $dir; $config['width'] = 650;//pre-configured width to be set on image $config['height'] = 310;//pre-configured height to be set on image $config['thumb'] = true;// boolean type - specific if that image has thumb copy image as well $config['thumb_width'] = 25;//pre-configured width to be set on thumb image $config['thumb_height'] = 15;//pre-configured height to be set on thumb image $config['water_mark'] = false;//boolean type - specific if that image will have water mark. If true, the water mark path must be send as second parameter. $config['transparency'] = false; $config['square'] = true;// boolean type - specific if that image has square copy image as well $config['square_width'] = 200;//pre-configured width to be set on square image $config['square_height'] = 200;//pre-configured height to be set on square image generatorSDK = new GeneratorImageSDK($config); try{ $base64 = 'base 64 here' // on this site you can get 64 base from a image - https://www.base64-image.de/ $photo = getGenerateImageSDK()->generatePhoto($base64); getGenerateImageSDK()->setPicture($photo); $photo = getGenerateImageSDK()->automaticResize(); getGenerateImageSDK()->setPicture($photo); $photo = getGenerateImageSDK()->createImages(); } catch (ImageException $e) { $photo['error'] = array( "code" => 'F'.sprintf("%02d", $e->getCode()), "status" => $e->getStatus(), "description" => $e->getMessage() ); echo $photo; } catch (Exception $e) { $photo['error'] = array( "code" => 'F'.sprintf("%02d", $e->getCode()), "status" => 'PictureError', "description" => $e->getMessage() ); echo $photo; } echo $photo; }
文档
进行中。
测试
进行中。
贡献
请随时提交您的拉取请求,贡献建议或报告问题。