Home > Backend Development > PHP Tutorial > Powerful PHP image processing class

Powerful PHP image processing class

巴扎黑
Release: 2016-11-08 13:32:11
Original
2501 people have browsed it

* Basic image processing, used to complete image indentation and watermark addition

* When the watermark image exceeds the target image size, the watermark image can automatically adapt to the target image and shrink

* The watermark image can be set to merge with the background

<?php
//JPG格式
require_once(&#39;lib/thumb.class.php&#39;);
$t = new ThumbHandler();
// 基本使用
$t->setSrcImg("img/test1.jpg");
$t->setDstImg("tmp/new_test1.jpg");
$t->setDstImgBorder(4,"#dddddd");
// 指定缩放比例
$t->createImg(300,200);
?>
<?php
//GIF格式
require_once(&#39;lib/thumb.class.php&#39;);
$t = new ThumbHandler();
// 基本使用
$t->setSrcImg("img/test2.gif");
$t->setDstImg("tmp/new_test2.gif");
$t->setDstImgBorder(4,"#dddddd");
// 指定缩放比例
$t->createImg(100,100);
?>
<?php
//PNG格式
require_once(&#39;lib/thumb.class.php&#39;);
$t = new ThumbHandler();
// 基本使用
$t->setSrcImg("img/test3.png");
$t->setDstImg("tmp/new_test3.png");
$t->setDstImgBorder(4,"#dddddd");
//指定压缩级别(0~9),重要
$t->setImgDisplayQuality(9);
// 指定缩放比例
$t->createImg(50,50);
?>
<?php
//JPG格式
require_once(&#39;lib/thumb.class.php&#39;);
$t = new ThumbHandler();
// 基本使用
$t->setSrcImg("img/test1.jpg");
$t->setMaskFontColor("#000000");
//设置文字水印
$t->setMaskWord("test");
//指定水印位置
$t->setMaskPosition(4);
$t->setDstImg("tmp/new_test4.jpg");
// 指定缩放比例
$t->createImg(300,280);
?>
<?php
require_once(&#39;lib/thumb.class.php&#39;);
$t = new ThumbHandler();
$t->setSrcImg("img/test1.jpg");
// 指定字体文件地址
$t->setMaskFont("fonts/TitilliumMaps29L002.otf");
$t->setMaskFontSize(20);
$t->setMaskFontColor("#000000");
$t->setMaskWord("hello world");
//设置水印横向偏移
$t->setMaskOffsetX(50);
//设置水印纵向偏移
$t->setMaskOffsetY(55);
//设置文字合并程度
$t->setMaskTxtPct(20);
//设置缩略图边框
$t->setDstImg("tmp/new_test5.jpg");
$t->setDstImgBorder(10,"#dddddd");
$t->createImg(300,200);
?>
<?php
//   自动裁切:
//    程序会按照图片的尺寸从中部裁切最大的正方形,并按目标尺寸进行缩略
require_once (&#39;lib/thumb.class.php&#39;);
$t = new ThumbHandler ();
$t->setSrcImg ( "img/test1.jpg" );
$t->setCutType ( 1 ); //这一句就OK了
$t->setDstImg ( "tmp/new_test6.jpg" );
$t->createImg ( 300, 200 );
?>
<?php
//手工裁切:
//    程序会按照指定的位置从源图上取图
require_once (&#39;lib/thumb.class.php&#39;);
$t = new ThumbHandler ();
$t->setSrcImg ( "img/test1.jpg" );
$t->setCutType ( 2 ); //指明为手工裁切
$t->setSrcCutPosition ( 100, 100 ); // 源图起点坐标
$t->setRectangleCut ( 300, 200 ); // 裁切尺寸
$t->setDstImg ( "tmp/new_test7.jpg" );
$t->createImg ( 300, 200 );
?>
Copy after login


Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template