fraserreed / meme-puush
将表情包生成到本地文件,屏幕回显或使用他们的API上传到puu.sh
v1.0.2
2014-04-25 02:30 UTC
Requires
- php: >=5.3.3
- guzzle/guzzle: ~3.8
Requires (Dev)
- phpunit/phpunit: 3.7.*
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2024-09-28 15:39:22 UTC
README
使用Imagick的表情包生成器。可以是输出本地文件路径、屏幕输出或使用Puu.sh API上传到Puu.sh。需要Puu.sh API密钥(http://puu.sh)
安装
使用 composer 在您的应用程序中安装此包。
在require部分,添加以下依赖项
"fraserreed/meme-puush": "~1.0"
用法
首先使用可访问的图像URL初始化图像对象
use MemePuush\Image;
$image = new Image( $img );
如果图像路径不存在,在尝试输出表情包图像时会抛出异常。
然后设置输出格式。选项在Image
类的常量中可用:Image::PUUSH
(将使用Puu.sh API密钥上传结果),Image::FILE
(将本地存储结果并提供输出文件名)和Image::SCREEN
(将结果输出到浏览器)。
$image->setOutputFormat( Image::PUUSH, '<puu.sh_api_key>' );
如果存储结果本地或输出到屏幕,则不需要puu.sh API密钥。
$image->setOutputFormat( Image::FILE );
设置标题字符串,用于顶部标题或底部标题(或两者都设置)
$image->setTopCaption( "top caption text" );
$image->setBottomCaption( "bottom caption text" );
最后输出结果。您对响应的处理取决于输出格式
$outputContent = $image->output();
switch( $output )
{
case 'screen':
header( 'Content-type: image/jpg' );
echo file_get_contents( $outputContent );
break;
case 'file':
echo $outputContent;
break;
case 'puush':
echo json_encode( array( 'url' => $outputContent ) );
break;
}
示例
可以在 public/index.php
中看到一个创建表情包的(非常丑陋的)示例UI,使用三种可用方法