定制 ride/lib-image 二次开发

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

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

ride/lib-image

Composer 安装命令:

composer require ride/lib-image

包简介

Image processing library of the Ride framework

README 文档

README

Image processing library of the PHP Ride framework.

You need GD or Imagick on your server to use this library.

What's In This Library

Image

The Image interface is the base of this library.

Through this interface, you can:

  • read and write images
  • get information about your image like the dimension
  • basic manipulations like resizing and cropping

The DrawImage interface extends from Image and adds methods to draw points, lines, ... on the image.

Implementations are available for GD and Imagick.

ImageFactory

The ImageFactory interface offers a generic way to create the instances needed to work with images.

A generic implementation is provided through GenericImageFactory.

Point

The Point interface is to define a coordinate on an X-Y axis. It's used for image manipulations. A point can go positive or negative on an axis.

A generic implementation is provided through GenericPoint.

Dimansion

The Dimension interface defines a dimension of an image or manipulation.

A generic implementation is provided through GenericDimension.

Transformation

The Transformation interface offers a way to apply batch image manipulations.

There are implementations available for crop, resize, flip, blur, grayscale, watermark and chain manipulations.

Blur

Blurs your image.

This transformation has following options:

  • radius: optional and defaults to 10

Crop

Crops your image by resizing it first to an optimal dimension.

This transformation requires the following options:

  • width: width to crop to in pixels
  • height: height to crop to in pixels

Flip

Flips your image over the X-axis and/or the Y-axis.

This transformation requires the following options:

  • mode: can be horizontal, vertical or both.

Grayscale

Converts your image to a grayscaled image.

This transformations has no options.

Resize

Resizes your image to fit a maximum width and/or height.

This transformation requires one of the following options:

  • width: maximum width of the resulting image
  • height: maximum height of the resulting image

Watermark

Adds a watermark to your image.

This transformation has the following options:

  • x: Point on the X-axis, defaults to 0
  • y: Point on the Y-axis, defaults to 0
  • watermark: relative path to the watermark image

Optimizer

The Optimizer interface can be used to implement optimalizations on image files. It's intented to optimize the file sizes but can be used for other purposes as well.

A generic implementation is provided through GenericOptimizer.

GenericOptimizer

The generic image optimizer uses the following binaries on your system:

  • pngcrush
  • optipng
  • jpegoptim
  • jpegtran (libjpeg-turbo-progs or libjpeg-progs)
  • gifsicle

Note: Unexistant binaries are ignored.

NullOptimizer

No optimization is performed by this optimizer.

Color

The Color interface offers an easy way to work with colors.

The interface is currently implemented for the RGB and the HSL color model.

ColorScheme

The ColorScheme interface is to generate a number of colors for a specified base color.

The interface is currently implemented for monochomatic and complementary schemes.

Code Sample

Check this code sample to see the possibilities of this library:

<?php

use ride\library\image\exception\ImageException;
use ride\library\image\GenericImageFactory;
use ride\library\image\Image;
use ride\library\system\file\File;

function foo(File $file) {
    // create an image factory, this one uses GD
    $imageFactory = new GenericImageFactory('gd');
    
    // use the image factory to create an image
    $image = $imageFactory->createImage();
    
    try {
        // read an image file
        $image->read($file);
    } catch (ImageException $exception) {
        // file could not be read or invalid image
        return false;
    }
    
    // get some properties of the image
    $hasTransparancy = $image->hasAlphaTransparancy();
    $transparentColor = $image->getTransparentColor();
    $dimension = $image->getDimension();
    
    $dimension->getWidth();
    $dimension->getHeight();
    
    // do some manipulations
    $dimension = $dimension->setWidth($dimension->getWidth() / 2);
    $image = $image->resize($dimension);
    
    $dimension = $dimension->setHeight($dimension->getHeight() / 2);
    $image = $image->crop($dimension);
    
    $image = $image->flip(Image::MODE_HORIZONTAL);
    $image = $image->rotate(90);
    $image = $image->blur();
    $image = $image->convertToGrayscale();
    
    // write the result back to the file
    $image->write($file);
}

Implementations

For more examples, you can check the following implementation of this library:

Installation

You can use Composer to install this library.

composer require ride/lib-image

ride/lib-image 适用场景与选型建议

ride/lib-image 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.77k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2014 年 02 月 21 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 ride/lib-image 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 ride/lib-image 我们能提供哪些服务?
定制开发 / 二次开发

基于 ride/lib-image 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

  • Stars: 0
  • Watchers: 8
  • Forks: 0
  • 开发语言: PHP

其他信息

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