PHP code example of estart / image
1. Go to this page and download the library: Download estart/image 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/ */
estart / image example snippets
use EStart\\image\\ImageFactory;
// 设置源图片内容
$img = ImageFactory::create((file_get_contents('src_image/1.png'));
// 生成200x200的缩略图,超过比例截掉
$imgContent = $img->thumb(200, 200);
// 保存图片
file_put_contents('dist_image/thumb.png.cut_100x200.jpg', $imgContent);
// 生成100x200的缩略图,超过比例则补白色背景
$imgContent = $img->thumb(100, 200, false);
// 保存图片
file_put_contents('dist_image/thumb.png.uncut_100x200.jpg', $imgContent);
// 打水印
$imgContent = $img->watermark('src_image/logo.png');
// 保存图片
file_put_contents('dist_image/water1.jpg', $imgContent);