noam148/yii2-image-resize

一个用于动态调整图片大小的Yii2组件

安装量: 39,889

依赖者: 8

建议者: 0

安全: 0

星标: 9

关注者: 5

分支: 8

开放问题: 2

类型:yii2-extension

1.1.0 2018-02-18 19:23 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:14:52 UTC


README

一个用于调整图片大小并将其存储在缓存文件夹中的Yii2组件

安装

安装此扩展的首选方式是通过composer

  • 运行以下命令之一:
php composer.phar require "noam148/yii2-image-resize" "*"

或者

"noam148/yii2-image-resize" : "*"

将以下内容添加到您的应用程序的composer.json文件的require部分。

  • 在您的应用程序配置文件的components部分添加一个新的组件,例如
'components' => [
    'imageresize' => [
		'class' => 'noam148\imageresize\ImageResize',
		//path relative web folder. In case of multiple environments (frontend, backend) add more paths 
		'cachePath' =>  ['assets/images', '../../frontend/web/assets/images'],
		//use filename (seo friendly) for resized images else use a hash
		'useFilename' => true,
		//show full url (for example in case of a API)
		'absoluteUrl' => false,
	],
],

使用方法

如果您想要获取一个图片的URL

/*
 * $sImageFilePath_id: (required) path to file
 * $width/$height: (required) width height of the image
 * $mode: "outbound", "inset" or "{horz}:{vert}" where {horz} is one from "left", "cetrer", "right" and {vert} is one from "top", "center", "bottom"
 * $$quality: (1 - 100)
 * $chosenFileName: if config -> components -> imageresize -> useFilename is true? its an option to give a custom name else use original file name
 */
\Yii::$app->imageresize->getUrl($sImageFilePath, $width, $height, $mode, $quality, $chosenFileName);

如果您有任何问题、建议或反馈?请告诉我!