定制 depage/graphics 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

depage/graphics

Composer 安装命令:

composer require depage/graphics

包简介

depage-graphics is a helper class to get resized and optimized images and thumbnails.

README 文档

README

depage-graphics is a helper class to get resized and optimized images and thumbnails.

Latest Stable Version Build Status

Features

  • supports gd as basic image resizing method
  • support imagemagick and graphicsmagick binaries for better image quality support
  • support external tools to optimize images like
    • jpegtran
    • jpegoptim
    • optipng
    • pngcrush
  • composer support

You can compare depage-graphics to SLIR, Smart Lencioni Image Resizer. But where SLIR is only gd-based, you can use Imagemagick or Graphicsmagick as conversion tools to achieve better image quality.

Basic Usage as Image Service

You can use the graphics class as an image service to automatically resize, crop, convert and optimize your images, or to generate thumbnails.

To convert your image you add specific action to your image:

/path-to/image.jpg.resize-400x400.jpg
/path-to/image.jpg.r400x400.jpg

/path-to/image.jpg.thumb-100x75.jpg
/path-to/image.jpg.t100x75.jpg

/path-to/image.jpg.crop-200x200-10x10.jpg
/path-to/image.jpg.c200x200-10x10.jpg

You can also chain actions and parameters:

/path-to/image.png.resize-400x400.quality-50.background-ffffff.jpg
/path-to/image.png.r400x400.q50.bg-ffffff.jpg

This would resize your image to 400x400px set the jpeg quality to 50 and add a white background for transparent pixels.

Basic image service

Basic usage as image service with the gd library and no image optimization:

<?php
    require_once(__DIR__ . "/php/Graphics/Graphics.php");

    $imgurl = new Depage\Graphics\Imgurl();
    $imgurl->render()->display();

Extended Usage with Options

Extended usage as image service with the imagemagick as conversion utility and jpegtran and optipng as optimization tools:

<?php
    require_once(__DIR__ . "/php/Graphics/Graphics.php");

    $imgurl = new Depage\Graphics\Imgurl(array(
        'extension' => "im",
        'executable' => "/usr/bin/convert",
        'optimize' => true,
        'optimizers' => array(
            'jpegtran' => "/usr/bin/jpegtran",
            'optipng' => "/usr/bin/optipng",
        ),
    ));
    $imgurl->render()->display();

Usage as Image-Editing/Conversion Tool

<?php
    require_once(__DIR__ . "/php/Graphics/Graphics.php");

    $graphics = new Depage\Graphics\Graphics(array(
        'extension' => "im",
        'executable' => "/usr/bin/convert",
        'optimize' => true,
        'optimizers' => array(
            'jpegtran' => "/usr/bin/jpegtran",
            'optipng' => "/usr/bin/optipng",
        ),
    ));
    $graphics->addResize(400, 400);
    $graphics->addBackground("#ffffff");

    $graphics->render("sourceImage.png", "targetImage.jpg");

Webserver Configuration

nginx

location /basedirectory {
    location ~ (?i)/basedirectory/(.*)\.(jpg|jpeg|gif|png)\.([^/]*)\.(jpg|jpeg|gif|png)$ {
        rewrite (?i)^(/basedirectory)/(?!lib/cache/graphics)(.*)$ $1/lib/cache/graphics/$2 last;

        try_files $uri /basedirectory/lib/global/getimage.php;
    }

    try_files $uri $uri/;
}

Apache

@todo

.htacess

RewriteEngine       on
RewriteBase         /

RewriteCond         %{REQUEST_FILENAME}   !-s
RewriteRule         ^(?!lib/cache/graphics)(.*)\.(jpg|jpeg|png|gif)\.([^/]*)\.(jpg|jpeg|png|gif)$ /lib/cache/graphics/$0

RewriteCond         %{REQUEST_FILENAME}   !-s
RewriteRule         ^lib/cache/graphics/(.*)\.(jpg|jpeg|png|gif)\.([^/]*)\.(jpg|jpeg)$ /lib/global/getimage.php [T=image/jpeg]

RewriteCond         %{REQUEST_FILENAME}   !-s
RewriteRule         ^lib/cache/graphics/(.*)\.(jpg|jpeg|png|gif)\.([^/]*)\.(png)$ /lib/global/getimage.php [T=image/png]

RewriteCond         %{REQUEST_FILENAME}   !-s
RewriteRule         ^lib/cache/graphics/(.*)\.(jpg|jpeg|png|gif)\.([^/]*)\.(gif)$ /lib/global/getimage.php [T=image/gif]

Install Using Composer

Get composer at http://getcomposer.org and then just add this to your composer.json.

{
    "require": {
        "depage/graphics": "dev/master"
    }
}

Now run

composer install

to install the current version of depage-graphics into your vendor dir.

Prerequisites

  • PHP 5.3 with following modules
  • gd support
  • external binaries (optional)
    • convert
    • gm
    • jpegtran
    • jpegoptim
    • optipng
    • pngcrush

For more information

You can fork us at: http://github.com/depage/depage-graphics/

For more information about depage-cms go to: http://www.depagecms.net/

License (dual)

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-02-25