PHP code example of lshorz / imagelib

1. Go to this page and download the library: Download lshorz/imagelib library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

lshorz / imagelib example snippets


composer 


use Lshorz\Imagelib\Image;

$file = 'uploads/test.gif'; //image path

$img = Image::open($file);

//生成缩略图后保存
$img->thumb(300, 200, null, $img::THUMB_AUTO)->save('uploads/test_thumb.gif');

//缩略图也支持自动计算长,高比例最后生成http响应,例如:
echo $img->thumb(null, 200)->response('gif');


use Lshorz\Imagelib\Image;

$file = 'uploads/test.jpg';
$warter = 'assest/water.png';

$img = Image::open($file);

//先裁剪图像再缩放,最后生成base64编码的图像code
$imageCode = $img->crop(800, 800, 0, 0)->resize(300, 200, true)->waterMark($warter, $img::POS_BOTTOM_RIGHT)->encode('data-url', 90);

//输出该图像
echo "<img src='{$imageCode}' />";