Giter VIP home page Giter VIP logo

cakephp-resize's Introduction

CakePHP Resize images

Resize images in web application by url.

Install Cookies

  • 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.

Requirements

  • PHP >= 7.1.x
  • GD exension enabled
  • CakePHP >= 3.6.x

Composer

Add following statement in require area.

{
    // ...
    "require": {
        "ext-gd": "*",
    }
    // ...
}

Load in AppView

Load Resize helper in src > View > AppView.php in initialize method like below.

public function initialize()
{
    // ...
    $this->loadHelper('Resize');
    // ...
}

Image URL

Resize URL to use in template.

If you want multiple folder tree structure write path with '--' between folders.

Example

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')

Image HTML element

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 url
  • proportional - 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 = [])

Example

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 ;)

cakephp-resize's People

Contributors

mrred85 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.