PHPThumb图片处理实例
这篇文章主要介绍了PHPThumb图片处理实例,例如生成缩略图、图片尺寸调整、图片截
下载地址(github.com/masterexploder/PHPThumb)。
注意这个类库有一个重名的叫phpThumb,只是大小写的差别,所以查找文档的时候千万注意。
在网站建设过程中,需要处理图片的地方多不胜数,用PHP的图片函数处理图片,十分繁琐。而且对新手来讲十分不好掌握。现在我们可以用PHPThumb类库来处理图片,包括,图片尺寸调整,图片截取,图片加水印,图片旋转等等功能。
使用演示:
复制代码 代码如下:
//加载类库文件
require_once 'path/to/ThumbLib.inc.php';
//实例化类库,传入你要处理的图片的地址可以是网络地址,也可以是本地地址
$thumb = PhpThumbFactory::create('http://www.jb51.net/');
//把图片等比缩小到最大宽度 100px或者最高100px,当只输入一个参数的时候,是限制最宽的尺寸。
$thumb->resize(100, 100);
//把图片等比缩小到原来的百分数,比如50就是原来的50%。
$thumb->resizePercent(50);
//截取一个175px * 175px的图片,注意这个是截取,超出的部分直接裁切掉,不是强制改变尺寸。
$thumb->adaptiveResize(175, 175);
//从图片的中心计算,截取200px * 100px的图片。
$thumb->cropFromCenter(200, 100);
//截图,前两个参数分别是需要解出的图片的右上角的坐标X,Y。 后面两个参数是需要解出的图片宽,高。
$thumb->crop(100, 100, 300, 200);
//把图片顺时针反转180度
$thumb->rotateImageNDegrees(180);
//保存(生成)图片,你可以保存其他格式,详细参考文档
$thumb->save( 'NewPath/Of/image.jpg ' );
这个类库还有更多功能就不多做介绍了,如果你也在开发PHP网站过程中需要处理图片不妨阅读一下这个类库的文档,保证你处理图片很简单,再也不用和那十几个烦人的php图片处理函数打交道了!
另外一个强大的PHP图片缩略图类:phpThumb
该类除了缩放图片外,还能将图片转换成不同的格式输出(比如将GIF格式的图片输出为PNG格式),其特色功能还包括色彩、特效等
官方网址:
一般只需要下面的文件就可以了:
[code]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
Adjust the path to phpThumb according to where you place the phpThumb files.

[code]
其实phpThumb的功能比我原先想象的要强大一些,下面把他的其他一些有用的参数列一下:
src:目标图片的地址
w:输出图片的宽度
h:输出图片的高度(如果不指定他将按w参数等比缩放)
q:输出如果是JPG格式的,,可以规定它的输出质量
bg:输出时的背景(如果需要)
sw、sh、sx、sy:局部输出,宽高、起始位置
f:输出格式,可以为jpeg、png、gif、ico
sfn:输出gif动画中的某一帧
fltr[]:滤镜,可以有很多效果,包括锐化、模糊、旋翻转、水印、边框、遮照、色彩调整等

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



Using Imgscalr for image processing in Java API development With the development of mobile Internet and the popularity of Internet advertising, images have become an indispensable element in many applications. Whether it is displaying products, building social circles, or enhancing user experience, images play an important role. In applications, it is often necessary to perform operations such as cropping, scaling, and rotating images, which requires the use of some image processing tools. Imgscalr is a very commonly used image in Java API development.

Golang image processing: How to perform color gradient and grayscale mapping of images Introduction: With the development of digital media, image processing has become an indispensable part of our daily life. In the Go language, we can use some libraries for image processing, such as github.com/disintegration/imaging. This article will introduce how to use this library to perform color gradient and grayscale mapping of images. 1. Introduce the library First, we need to introduce github.com/ in the Go project

Overview of how to use Golang to enhance borders and edges on images: In the field of image processing, border and edge enhancement is a commonly used technique that can effectively improve the visual effects of images and improve the accuracy of image recognition. This article will introduce how to use Golang language to perform border and edge enhancement operations on images, and provide corresponding code examples. Note: This article assumes that you have installed and configured the Golang development environment in your local environment. Import dependency packages First, we need to import the following dependency packages for image processing operations

How to use Python to add noise to pictures Introduction: With the development of technology, digital image processing has become a common image processing method. Among them, adding noise to the image is an important step in image processing. By adding noise, the realism and complexity of the image can be improved. This article will introduce how to use Python to add noise to images and provide relevant code examples. 1. Understanding image noise Image noise refers to random disturbances that affect image quality and clarity. Common image noises include Gaussian noise,

Laravel Development Suggestions: How to Optimize Image Processing and Caching Introduction In modern web development, image processing and caching is a common and important issue. Optimizing image processing and caching strategies not only improves website performance and user experience, but also reduces bandwidth consumption and server load. This article will explore methods and suggestions on how to optimize image processing and caching in Laravel development. 1. Choose the appropriate image format Choosing the appropriate image format is the first step in optimizing image processing. Common image formats include JPEG and PNG

How to handle image caching and preloading in Vue? When developing Vue projects, we often need to deal with caching and preloading of images to improve website performance and user experience. This article will introduce some methods of handling image caching and preloading in Vue, and give corresponding code examples. 1. Image caching uses image lazy loading (LazyLoading) Image lazy loading is a technology that delays loading images, that is, the image is not loaded until the page scrolls to the location of the image. This reduces requests for image resources when the page is first loaded

How to use Golang to mask and mask effects on pictures In modern image processing, masking and masking effects are very common special effects. This article will introduce how to use Golang to mask and mask effects on images. Installing the Necessary Libraries Before we start, we need to install some necessary libraries to process images. Run the following command to install the necessary libraries: goget-ugithub.com/fogleman/gggoget-ugolang.org/x/im

How to use PHP to blur images Image blurring is a common operation in image processing, which can add a blur effect to the image to make it look softer and more artistic. In PHP, we can use the GD library to blur images. The following will introduce how to use PHP to blur images, and attach corresponding code examples. Installing the GD library Before starting, you need to make sure that your server has the GD library installed. You can do this by adding the phpinfo() function to your PHP file
