miseio/cloudinary-bundle

Cloudinary 包装器

v0.2 2017-01-05 10:30 UTC

This package is not auto-updated.

Last update: 2024-09-28 18:34:54 UTC


README

Latest Stable Version Latest Unstable Version License Build Status Code Climate

MisteioCloudinaryBundle 是从 laravel4-cloudinary (感谢 Teeplus) 和 cloudinary-bundle (感谢 Speicher210) 分支出来的 Symfony2/3 Bundle。你可以将其作为服务使用,并实现了一些针对 Twig 的扩展。Cloudinary 库 v1.7.1

安装

通过 Composer

$ composer require misteio/cloudinary-bundle

或在 composer.json 文件中

"misteio/cloudinary-bundle": "dev-master"

app/AppKernel.php 中注册此包

public function registerBundles()
{
    return array(
        // ...
        new Misteio\CloudinaryBundle\MisteioCloudinaryBundle(),
        // ...
    );
}

配置

config.yml 中配置与 Cloudinary 的连接

misteio_cloudinary:
  cloud_name: yourCloudRegistrationName
  api_key: yourApiKey
  secret_key: yourSecretApiKey

用法

此包装器 API 提供简单的上传、重命名、删除、标签管理和从原始 Cloudinary 类方法中获取完整功能的操作。你可以通过依赖注入组件 (DIC) 服务来使用它。

	$cloudinary = $this -> container -> get('misteio_cloudinary_wrapper');

上传图片

	$cloudinary -> upload('path/to/file', 'name', $tags, $options)

上传视频(最后一个参数用于大文件)

	$cloudinary -> uploadVideo('path/to/file', 'name', $tags, true)

显示图片

	$cloudinary -> show('public_name', array('width' => 150, 'height' => 150, 'crop' => 'fit', 'radius' => 20));

使用 HTTPS 显示图片

  $cloudinary -> show('public_name', array('width' => 150, 'height' => 150, 'crop' => 'fit', 'radius' => 20, 'secure' => true));

显示视频

	$cloudinary -> showVideo('public_name', array('width' => 150, 'height' => 150, 'crop' => 'fit', 'radius' => 20));

使用 HTTPS 显示视频

  $cloudinary -> showVideo('public_name', array('width' => 150, 'height' => 150, 'crop' => 'fit', 'radius' => 20, 'secure' => true));

更多文档请参阅 cloudinary.com

重命名文件

	$cloudinary -> rename('from_public_id', 'to_public_id');

删除文件

	$cloudinary -> destroy('public_id');

通过标签管理

    $cloudinary -> addTag('my_tag_1', array('my_public_id', 'my_public_id_2'));
    $cloudinary -> removeTag('my_tag_2', array('my_public_id', 'my_public_id_2'));
    $cloudinary -> replaceTag('my_tag_3', array('my_public_id', 'public_id_2'));

使用 Twig 显示图片

	{{ 'my_public_id'|cloudinary_url({"width" : 150, "height" : 150, "crop" : "fill", "radius" : 20}) }}

使用 HTTPS 和 Twig 显示图片

  {{ 'my_public_id'|cloudinary_url({"width" : 150, "height" : 150, "crop" : "fill", "radius" : 20, "secure" : true}) }}

使用 Twig 显示视频

	{{ 'my_public_id'|cloudinary_url_video({"width" : 150, "height" : 150, "crop" : "fill", "radius" : 20}) }}

使用 HTTPS 和 Twig 显示视频

  {{ 'my_public_id'|cloudinary_url_video({"width" : 150, "height" : 150, "crop" : "fill", "radius" : 20, "secure" : true}) }}

安全性

如果你发现了一个安全漏洞,请通过电子邮件而不是使用问题跟踪器来报告。所有安全漏洞都将得到及时处理。

许可

此包装器是开源软件,采用MIT 许可证