Giter Club home page Giter Club logo

image-php's Introduction

Image.php

很多PHP框架竟然没有图片设定宽高居中剪裁的功能,比如CI,所以我自己封装了一个图片处理类:可设定宽高居中剪裁、设定宽高等比缩放、创建缩略图

提供了以下功能

1. 居中剪裁 (设定宽高)
2. 等比缩放 (设定宽高, 源图小于宽高的不做缩放)
3. 创建缩略图
4. 如果操作网络图片, 会在根目录生成"tmp.jpg" (用于测试)

生成用户头像 (Sample 1)

$img = new Image();

$config['source_image'] = '/www/img/4533070d32960cd35e726ddb715a1eac.jpg';
$config['width'] = 200;
$config['height'] = 200;
$img->initialize($config);
$img->crop();  // 剪裁

创建缩略图 (Sample 2)

$img = new Image();

$config['source_image'] = '/www/img/4533070d32960cd35e726ddb715a1eac.jpg';
$config['width'] = 200;
$config['height'] = 200;
$config['create_thumb'] = true;
$img->initialize($config);
$img->crop();  // 剪裁

等比压缩图片并创建缩略图 (Sample 3)

$img = new Image();

$config['source_image'] = '/www/img/4533070d32960cd35e726ddb715a1eac.jpg';
$config['width'] = 1280;
$config['height'] = 720;
$img->initialize($config);
$img->resize();  // 缩放

$config = array(); // 清空之前的配置

$config['source_image'] = '/www/img/4533070d32960cd35e726ddb715a1eac.jpg';
$config['width'] = 600;
$config['height'] = 450;
$config['create_thumb'] = true;
$config['thumb_marker'] = '_small';  // 默认为'_thumb'
$img->initialize($config);
$img->crop();  // 剪裁

image-php's People

Contributors

onanying avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.