承接 josbeir/image 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

josbeir/image

Composer 安装命令:

composer require josbeir/image

包简介

CakePHP 3.0 Image upload behavior

README 文档

README

Image behavior that works much like Cake's built in Translate Behavior by adding fields with image data to every entity the table returns.

  • Uploads can be either $_FILE based or just a string containing path. 'copy' or 'move_uploaded_file' is used accordingly.
  • Validating should be done by cake's nice validation options and is therefore not included in the behavior itself.
  • Image presets are generated using Intervention/Image. See the documentation page.

Notes

The behavior is very much a work in progress and should not be considered stable in any way.

Configuration parameters

  • fields: Fields used for images, should be the name of the field as key and the type as value (many, one)
  • presets: Array of presets containing a list of Intervention/Image methods and their parameters, can also be a callable function with the image object passed
  • path: The base path where the uploaded images should be stored
  • table: The table name of for storing the image data (see Config/Schema/images.sql)
  • manager: Settings for Intervention\Image\ImageManager (defaults to driver : imagick)

Usage

Install using composer

"require": {
	"josbeir/image": "~1.0"
}

And run php composer.phar install

Enable the plugin by adding it to bootstrap.php

Plugin::load('Image');

Init the database table by using cakephp's migrations

bin/cake migrations migrate -p Image

Enable the image behavior by adding it to the Table's initialize hook

	public function initialize(array $config) {
		$this->addBehavior('Image.Image', [
			'path' => WWW_ROOT . 'assets',
			'fields' => [
				'images' => 'many',
				'main' => 'one'
			],
		]);
	}

Image presets

Image manipulation is handled by Intervention/Image and configuring presets is pretty straightforward. In the example below the preset 'overview' is generated by looping trough various Intervention/Image helper functions

$this->addBehavior('Image.Image', [
	'path' => WWW_ROOT . 'assets',
	'presets' => [
		'overview' => [
			'resize' => [ 200, 200 ], // $image->resize(200, 200);
			'crop' => [ 150, 150] // $image->crop(150,150);
			'canvas' => function($image) {
			 	// you can use callback functions for more advanced stuff
				// do some fancy stuff here
				
				return $image;
			},
		]
	],
	'fields' => [
		'image' => 'one'
	],
]);

Helper

I've included a basic helper to render the images in your templates.

$this->Image->render($entity->field); // Original image
$this->Image->render($entity->field, [ 'preset' => 'presetName' ]); // Preset
$this->Image->render($entity->field, [ 'preset' => 'presetName', 'alt' => 'Cool image' ]); // Preset + image attributes
$this->Image->url($entity->field, 'presetName'); // Returns the image path with an optional preset argument

Shell

Simple shell to re-generate all presets for given model

bin/cake image

统计信息

  • 总下载量: 3.53k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 20
  • Watchers: 4
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-11-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固