wernerdweight/microbe-image-manager

为Microbe提供图像调整大小、裁剪和加密支持。

v2.0.0 2017-06-15 12:13 UTC

This package is auto-updated.

Last update: 2024-09-13 03:44:13 UTC


README

此实用程序为Microbe添加了图像调整大小和裁剪的支持。

安装

  1. 使用composer下载
	{
		"require": {
			"wernerdweight/microbe-image-manager": "~2.0"
		}
	}
  1. 设置配置
# app/config/microbe.yml
wd_image_manager:
	enabled: true
    upload_root: path/to/web/directory # public/uploads
    upload_path: relative/path/for/storing/images # e.g. images/image-manager
    secret: thisIsNotSecret # you can use app secret (%secret%) or any other custom secret (needed for encryption)
    versions:
        version_name_x:	# this key will be used as name of directory to where this version of images will be saved
            width: 200	# desired image width in pixels (if you ommit width or height image will keep its original dimensions)
            height: 200 # desired image height in pixels (if you ommit width or height image will keep its original dimensions)
            crop: true	# set this to true if you want the resulting image to have EXACTLY the dimensions specified (default false)
            watermark: # if you don't want your images to be watermarked, do not set this key at all
                file: absolute/path/to/watermark/file # e.g. %kernel.root_dir%/../web/watermark.png
                size: 50 # css-like watermark size; possible values: cover/contain/percentage (integer 0 - 100)
                position:
                    top: 50 # css-like position from top in percent (integer 0 - 100; default 100 - align to bottom)
                    left: 50 # css-like position from left in percent (integer 0- 100; default 100 - align to right)
        encrypted_version_name:
            encrypted: true	# if encrypted is set to true original image will be saved encrypted (intended for image download restrictions)
        ...
            

使用方法

控制器内部使用的代码

		/// get manager
		$im = $this->kernel->service('imageManager');
		
		/// upload your image file(s), create database records etc.
		...

		/// process image (one by one)
		/// 1st parameter ($file) is instance of WernerDweight\MicrobeImageManager\File\UploadedFile (mandatory)
		/// 2nd parameter is the filename of newly created file (mandatory)
		/// 3rd parameter is a path under upload_path from config (optional)
		$processedImageInfo = $im->processImage($file,'destination-filename','/optional/subpath');

许可证

此软件包受MIT许可证的约束。请参阅软件包根目录中的完整许可证。