Resize images in web application by url.
- Set resize routes from
config > routes.php
in yout routes.php - Copy the
src > Controller > Resize
to your Controller folder. - Copy the
src > View > Helper > ResizeHelper.php
to your Helper folder.
- PHP >= 7.1.x
- GD exension enabled
- CakePHP >= 3.6.x
Add following statement in require
area.
{
// ...
"require": {
"ext-gd": "*",
}
// ...
}
Load Resize helper in src > View > AppView.php
in initialize
method like below.
public function initialize()
{
// ...
$this->loadHelper('Resize');
// ...
}
Resize URL to use in template.
If you want multiple folder tree structure write path with '--' between folders.
Tree structure:
webroot
- files
--- media
Disk path: files/media
Resize folder path: files--media
Link parameter can be Null, True or False.
public function url(string $imageName, string $folder, int $width, int $height, $link = null, string $type = 'normal')
Create <img />
HTML element with resize URL as src
.
If you want multiple folder tree structure write path with '--' between folders.
Options:
_full
- Full base urlproportional
- True or False- any
<img />
tag option like: alt, border, style, class, etc.
public function image(string $imageName, string $folder, int $width, int $height, array $options = [])
Resize image.jpg
from webroot > files > media
folder and get the resize url.
echo $this->Resize->image('image.jpg', 'files--media', 150, 150, [
'proportional' => true
]);
echo $this->Resize->url('image.jpg', 'files--media', 150, 150);
Enjoy ;)