我正在为最新版本的CakePHP寻找灵活的图片上传和调整大小插件
答案 0 :(得分:2)
https://github.com/burzum/FileStorage
阅读readme.md,它可以做你想做的一切,5。将要求你添加自己的事件监听器,以允许自定义文件夹超过约定(不推荐任何方式)。开发分支还有一些更好的结构化文档。 This page is about the image processing part of it。它还附带单元测试,并从2.0 up to 2.5(此时即将推出的版本)进行测试。
UploadValidationBehavior将负责您想要的验证。在验证图像大小的情况下,ImageStorage模型实现了一种方法。
答案 1 :(得分:0)
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;
}
答案 2 :(得分:-1)
您好,您可以使用:Intervention Image
安装:
php composer.phar require intervention/image
代码:
use Intervention\Image\ImageManager;
$img = Image::make('public/foo.jpg');
$img->crop(100, 100, 25, 25);