0
votes

I am looking for a goof and flexible Image Upload and Resizing plugin for the Lastest version of CakePHP

  1. Upload Image based on MimeType
  2. Check the Width and Height min/max
  3. Able to Resize and Crop Center the Image to give max image visibility when cropped
  4. Renaming File names
  5. Specifying Custom Folders depending on the Model and relations.
3
Search, it was many times - kicaj

3 Answers

2
votes

https://github.com/burzum/FileStorage

Read the readme.md, it can do all you want, 5. will require you to add your own event listener to allow custom folders over convention (not recommended any way). The develop branch has some more and better structured documentation as well. This page is about the image processing part of it. It comes with unit tests as well and is tested from 2.0 up to 2.5 (upcoming version at this moment).

The UploadValidationBehavior will take care of the validation you want. In the case of validating image size, the ImageStorage model implements a method for that.

0
votes
function upload_image($data, $id) {
        $data['photo'] = $data['image_path'];
        unset($data['image_path']);
        $upData = array();
        if ($this->fnIsNotNull($data['photo']) && $data['photo']['error'] == 0) {
            $allowedExts = array("gif", "jpeg", "jpg", "png");
            $optionsUpload = array('org' => true, "thumbs" => array("width" => 270, "height" => 180));
            $fileUploaded = fileUpload($data['photo'], $data['id'] . "_category", CATEGORY_IMG_DIR, $allowedExts, $optionsUpload);
            if (isset($fileUploaded['success']) && fnIsNotNull($fileUploaded['success'])) {
                $upData = $fileUploaded['success'][0]['filename'];
            }
        }
        if (isset($id) && count($upData)) {
            $oldData = $this->get($id);
            $remvoeImg = $oldData->photo;
            $oldData->photo = $upData;
            $res = $this->save($oldData);
            if ($res && !empty($upData) && !empty($remvoeImg)) {
                @unlink(CATEGORY_IMG_DIR . $remvoeImg);
                @unlink(CATEGORY_IMG_DIR . "thumbs/" . $remvoeImg);
            }
            return $res;
        }
        return false;
    }
-1
votes

Hi you can use : Intervention Image

Install:

 php composer.phar require intervention/image

Code:

use Intervention\Image\ImageManager;
$img = Image::make('public/foo.jpg');
$img->crop(100, 100, 25, 25);