makeitbetter/thumbnail

创建缩略图的PHP类

v1.0.1 2017-10-22 07:12 UTC

This package is not auto-updated.

Last update: 2024-09-20 20:31:36 UTC


README

Thumbnail - 创建缩略图的PHP类。

演示: makeitbetter.su/projects/thumbnail

公共变量

public static $sourceFolder 图像源文件夹的路径。

public static $targetFolder 相对于web根的缩略图文件夹路径。

public static $webRoot Web根路径。默认 - $_SERVER['DOCUMENT_ROOT']

public static $paddingColor 填充缩略图填充的十六进制RGB颜色。默认 - ffffff。

public static $getThumbnailPathMethod 创建缩略图路径的函数。默认 - $this->_getThumbnailPath()

public $path 相对于源文件夹的图像路径。

public $stretch 是否拉伸小于缩略图大小的图像。默认 - false

public $crop 是否裁剪比例不符合缩略图比例的图像。默认 - false

public $width 缩略图宽度。默认 - 0 (使用源比例计算)

public $height 缩略图高度。默认 - 0 (使用源比例计算)

公共方法

public static of($path, $width = 0, $height = 0, $crop = false, $stretch = false) 返回新对象。

public width($width) 设置缩略图宽度。高度将使用源比例计算。返回自身。

public height($height) 设置缩略图高度。宽度将使用源比例计算。返回自身。

public size($width, $height) 设置缩略图的精确大小。返回自身。

public crop() 如果图像比例与缩略图比例不匹配,则裁剪图像。返回自身。

public contain() 按照可以在缩略图框架内(添加填充)缩放图像。返回自身。

public stretch() 将小图像拉伸到缩略图大小。返回自身。

public nostretch() 保持小图像的大小不变(添加填充)。返回自身。

public path() 如果不存在,则创建缩略图。返回其路径。当尝试将对象转换为字符串时,将调用此方法

#!php
<img src="<?php echo Thumbnail::of('images/example.jpg', 100)->path();?>" />
<!-- equals : -->
<img src="<?php echo Thumbnail::of('images/example.jpg', 100);?>" />

public img($attributes = []) 将路径包裹在HTML标签 <img/> 中

#!php
<img src="<?php echo Thumbnail::of('images/example.jpg', 100);?>" class="thumbnail" />
<!-- equals : -->
<?php echo Thumbnail::of('images/example.jpg', 100)->img(['class' => 'thumbnail']);?>