noam148/yii2-image-resize

A Yii2 component for resizing images (on the fly)

Installs: 40 299

Dependents: 8

Suggesters: 0

Security: 0

Stars: 9

Watchers: 5

Forks: 8

Open Issues: 2

Type:yii2-extension

1.1.0 2018-02-18 19:23 UTC

This package is not auto-updated.

Last update: 2024-11-09 20:07:05 UTC


README

A Yii2 component for resizing images and store it in a cache folder

Installation

The preferred way to install this extension is through composer.

  • Either run
php composer.phar require "noam148/yii2-image-resize" "*"

or add

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

to the require section of your application's composer.json file.

  • Add a new component in components section of your application's configuration file, for example:
'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,
	],
],

Usage

If you want to get a image 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);

If you got questions, tips or feedback? Please, let me know!