acoustep/canvas
Composer 安装命令:
composer require acoustep/canvas
包简介
Simple GD Library class for resizing images
README 文档
README
Canvas is a simple PHP class for creating and manipulating image sizes with the GD Library.
Usage
Setting up the canvas
There are two ways to set up the canvas.
- Through the constructor
$canvas = \Acoustep\Canvas(500, 250, '#000000');
- Through methods
$canvas = \Acoustep\Canvas()->width(500)->height(250)->background('#000000');
Adding images
Images are added through the image method, you can add as many layers as you would like.
The first image added will be added to the bottom of the output. The rest will be layered on top of each other in the order they were added.
The image method takes two arguments: A string (The file along with the path to the file) and an array of arguments.
$canvas = \Acoustep\Canvas()->width(500)
->height(250)
->background('#000000')
->image('images/test.jpg', array('x' => 'left',
'y' => 'top',
'scale' => 'best'));
X can be an integer which is the offset from the canvas in pixels or left, centre or right.
Y can also be an integer for a specific offset, top, middle or bottom
Scale can be width, height, best or false.
- Width sets the image to fit best with the canvas width.
- Height sets the image to fit best with the canvas height.
- Best will try to figure out whether to use width or height for you.
- False will keep the image size the same as it was originally.
Outputting the image
There are three methods to output the image to the user. output(), filetype() and create().
- Filetype lets you set the image type. PNG, GIF and JPG are supported.
- Output lets you specify a filename to output the image to. If
NULLit will try to output to the current file - You will need to set the headers appropriately for it. - Create is used when you are ready to output the image to the user. This method is always called last.
Examples
Output to a file named 'output.png'
$canvas = \Acoustep\Canvas()->width(500)
->height(250)
->background('#000000')
->image('images/test.jpg', array('x' => 'left',
'y' => 'top',
'scale' => 'best'))
->filetype('png')
->output('output')
->create();
Output to the current page
header("Content-Type: image/png");
$canvas = \Acoustep\Canvas()->width(500)
->height(250)
->background('#000000')
->image('images/test.jpg', array('x' => 'center',
'y' => 'middle',
'scale' => 'width'))
->filetype('png')
->output(NULL)
->create();
统计信息
- 总下载量: 835
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2013-06-22