afxsoft / phpimagecache
基于 https://github.com/nielse63/php-image-cache,使用 psr-4 自动加载并移除无用组件的分支。
1.0.0
2014-09-29 23:13 UTC
Requires
- php: >=5.3.0
This package is not auto-updated.
Last update: 2024-09-29 06:02:36 UTC
README
Image Cache 是一个非常简单的 PHP 类,接受一个图像源,并将文件压缩和缓存,将其移动到新的目录,并返回图像的新源。
安装
通过打开终端并导航到您想要安装 Image Cache 的目录来安装 Composer。
在项目根目录执行以下 bash 命令进行安装
composer require afxsoft/phpimagecache:dev-master
基本用法:该类非常小,非常基础。首先,包含文件并初始化类
require_once 'ImageCache.php'; $imagecache = new Afxsoft\App\ImageCache();
可选:设置存放缓存图像的目录位置
$imagecache->cached_image_directory = dirname(__FILE__) . '/images/cached';
然后,引用要压缩的图像,并将新的图像源存储在一个变量中。在图像标签的 'src' 属性中输出此变量
$cached_src = $imagecache->cache( 'images/unsplash1.jpeg' ); /// <!-- later in your HTML --> <img src="<?php echo $cached_src; ?>" alt="Amazingly awesome photo">