PHPThumb image processing example code_PHP tutorial
Download address (github.com/masterexploder/PHPThumb).
Note that this class library has the same name called phpThumb, the only difference is in upper and lower case, so be careful when searching for documentation.
In the process of website construction, there are countless places where images need to be processed. It is very cumbersome to use PHP image functions to process images.
And it is very difficult for novices to master. Now we can use the PHPThumb class library to process images, including image resizing, image interception, image watermarking, image rotation and other functions.
Example:
<?<span php </span><span //</span><span 加载类库文件</span> <span require_once</span> 'path/to/ThumbLib.inc.php'<span ; </span><span //</span><span 实例化类库,传入你要处理的图片的地址可以是网络地址,也可以是本地地址</span> <span $thumb</span> = PhpThumbFactory::create('http://www.jbxue.com/'<span ); </span><span //</span><span 把图片等比缩小到最大宽度 100px或者最高100px,当只输入一个参数的时候,是限制最宽的尺寸。</span> <span $thumb</span>->resize(100, 100<span ); </span><span //</span><span 把图片等比缩小到原来的百分数,比如50就是原来的50%。</span> <span $thumb</span>->resizePercent(50<span ); </span><span //</span><span 截取一个175px * 175px的图片,注意这个是截取,超出的部分直接裁切掉,不是强制改变尺寸。</span> <span $thumb</span>->adaptiveResize(175, 175<span ); </span><span //</span><span 从图片的中心计算,截取200px * 100px的图片。</span> <span $thumb</span>->cropFromCenter(200, 100<span ); </span><span //</span><span 截图,前两个参数分别是需要解出的图片的右上角的坐标X,Y。 后面两个参数是需要解出的图片宽,高。</span> <span $thumb</span>->crop(100, 100, 300, 200<span ); </span><span //</span><span 把图片顺时针反转180度</span> <span $thumb</span>->rotateImageNDegrees(180<span ); </span><span //</span><span 保存(生成)图片,你可以保存其他格式,详细参考文档</span> <span $thumb</span>->save( 'NewPath/Of/image.jpg ' );
Another powerful PHP image thumbnail class: phpThumb
In addition to scaling images, this class can also convert images into different formats for output (such as outputting GIF format images into PNG format). Its special functions It also includes colors, special effects, etc.
Official website: http://phpthumb.sourceforge.net/
Generally, you only need the following files:
<span We'll be using phpThumb , the open source PHP script to generate thumbnails on the fly. Download and extract phpThumb to somewhere in your website folder. Now to use a rounded corner thumbnail of an image, simply use the img tag of HTML with src as </span><span <</span><span img </span><span src</span><span =”phpThumb.php?src=test.jpg&w=200&h=150&fltr[]=ric|20|20&f=png” </span><span /></span><span Adjust the path to phpThumb according to where you place the phpThumb files. </span><span <</span><span html</span><span ></span> <span <</span><span head</span><span ></span> <span </</span><span head</span><span ></span> <span <</span><span body</span><span ></span> <span <</span><span img </span><span src</span><span ="phpThumb/phpThumb.php?src=../images/test.jpg&w=400&fltr[]=fram|3|2|CC9966|333333|CCCCCC"</span><span alt</span><span =""</span><span ></span> <span </</span><span body</span><span ></span> <span </</span><span html</span><span ></span>
src: The address of the target image
w: The width of the output image
h: The height of the output image (if not specified, it will be scaled according to the w parameter)
q: If the output is in JPG format Yes, you can specify its output quality
bg: background during output (if needed)
sw, sh, sx, sy: local output, width, height, starting position
f: output format, you can For jpeg, png, gif, ico
sfn: output a certain frame in the gif animation
fltr[]: filter, which can have many effects, including sharpening, blurring, rotation, watermark, border, mask Photo, color adjustment, etc.
Original address: http://www.jbxue.com/article/php/20250.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The combination of Vue.js and ASP.NET provides tips and suggestions for performance optimization and expansion of web applications. With the rapid development of web applications, performance optimization has become an indispensable and important task for developers. As a popular front-end framework, Vue.js combined with ASP.NET can help us achieve better performance optimization and expansion. This article will introduce some tips and suggestions, and provide some code examples. 1. Reduce HTTP requests The number of HTTP requests directly affects the loading speed of web applications. pass

How to correctly use and optimize the MySQL connection pool in ASP.NET programs? Introduction: MySQL is a widely used database management system that features high performance, reliability, and ease of use. In ASP.NET development, using MySQL database for data storage is a common requirement. In order to improve the efficiency and performance of database connections, we need to correctly use and optimize the MySQL connection pool. This article will introduce how to correctly use and optimize the MySQL connection pool in ASP.NET programs.

Translator | Reviewed by Chen Jun | Chonglou In the 1990s, when people mentioned software programming, it usually meant choosing an editor, checking the code into the CVS or SVN code base, and then compiling the code into an executable file. Corresponding integrated development environments (IDEs) such as Eclipse and Visual Studio can integrate programming, development, documentation, construction, testing, deployment and other steps into a complete software development life cycle (SDLC), thus improving the work of developers. efficiency. In recent years, popular cloud computing and DevSecOps automation tools have improved developers' comprehensive capabilities, making it easier for more enterprises to develop, deploy and maintain software applications. Today, generative AI is the next generation development

How to reconnect to MySQL in ASP.NET program? In ASP.NET development, it is very common to use the MySQL database. However, due to network or database server reasons, the database connection may sometimes be interrupted or time out. In this case, in order to ensure the stability and reliability of the program, we need to re-establish the connection after the connection is disconnected. This article will introduce how to reconnect MySQL connections in ASP.NET programs. To reference the necessary namespaces first, reference them at the head of the code file

The combination of Vue.js and ASP.NET enables the development and deployment of enterprise-level applications. In today's rapidly developing Internet technology field, the development and deployment of enterprise-level applications has become more and more important. Vue.js and ASP.NET are two technologies widely used in front-end and back-end development. Combining them can bring many advantages to the development and deployment of enterprise-level applications. This article will introduce how to use Vue.js and ASP.NET to develop and deploy enterprise-level applications through code examples. First, we need to install

How to correctly configure and use MySQL connection pool in ASP.NET program? With the development of the Internet and the increase in data volume, the demand for database access and connections is also increasing. In order to improve the performance and stability of the database, connection pooling has become an essential technology. This article mainly introduces how to correctly configure and use the MySQL connection pool in ASP.NET programs to improve the efficiency and response speed of the database. 1. The concept and function of connection pooling. Connection pooling is a technology that reuses database connections. At the beginning of the program,

How to correctly use and optimize the transaction performance of MySQL connection pool in ASP.NET programs? In ASP.NET programs, database transactions are a very important part. Transactions ensure the consistency and integrity of the database while also providing better performance. When using a MySQL database, it is essential to use connection pools to manage connection resources and optimize performance. First, let us briefly understand the concept of MySQL connection pool. The connection pool is a buffer pool of a group of connections. By pre-initializing a certain number of

The built-in objects in ASP.NET include "Request", "Response", "Session", "Server", "Application", "HttpContext", "Cache", "Trace", "Cookie" and "Server.MapPath": 1. Request, indicating the HTTP request issued by the client; 2. Response: indicating the HTTP response returned by the web server to the client, etc.
