GithubHelp home page GithubHelp logo

thumb's Introduction

Thumb是什么?

Thumb是一个图片等比例缩放的PHP依赖,使用Thumb可以轻松生成不变形的缩略图。

安装

通过composer,这是推荐的方式,可以使用composer.json 声明依赖,或者直接运行下面的命令。

composer require aileshe/thumb:*

放入composer.json文件中

    "require": {
        "aileshe/thumb": "*"
    }

然后运行

composer update

基本用法

  1. 生成一张缩略图
    $src = './public/upload/img_12.jpg'; // 原图路径
    $output = './public/upload/img_12_thumb.jpg'; // 输出保存文件名
    $width = 300; // 预生成缩略图的宽
    $height = 200; // 预生成缩略图的高
    \Thumb\Thumb::out($src,$output,$width,$height);
  1. 生成缩略图直接输出图象到浏览器
    $src = './public/upload/img_12.jpg'; // 原图路径
    $width = 300; // 预生成缩略图的宽
    $height = 200; // 预生成缩略图的高
    \Thumb\Thumb::show($src,$width,$height);
  1. 生成缩略图直接输出图象到浏览器并保存缩略图
    $src = './public/upload/img_12.jpg'; // 原图路径
    $output = './public/upload/img_12_thumb.jpg'; // 输出保存文件名
    $width = 300; // 预生成缩略图的宽
    $height = 200; // 预生成缩略图的高
    \Thumb\Thumb::showOut($src,$output,$width,$height);

高级用法 - 自定义缩略剪裁

如一张纵向图片在固定宽高等比例缩放后得到的缩略图必须要剪裁部分,所以要么居中剪裁,要么顶部、底部剪裁再去掉多余部分。

缩略剪裁方式: middle、top、bottom (默认: 居中)
 ________________    ________________    ________________
 |                |  |                |  |                |
 |                |  |      top       |  |                |
 |________________|  |                |  |                |
 |                |  |________________|  |                |
 |     middle     |  |                |  |                |
 |                |  |                |  |________________|
 |----------------|  |                |  |                |
 |                |  |                |  |      bottom    |
 |                |  |                |  |                |
 |________________|  |________________|  |________________|

\Thumb\Thumb::out([原图路径],[缩图文件名],[缩略图宽],[缩略图高],[middle|top|bottom]);
\Thumb\Thumb::show([原图路径],[缩略图宽],[缩略图高],[middle|top|bottom]);
\Thumb\Thumb::showOut([原图路径],[缩图文件名],[缩略图宽],[缩略图高],[middle|top|bottom]);

联系

Author: Dejan
QQ : 673008865

thumb's People

Contributors

aileshe avatar

Watchers

haoht 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.