Home Backend Development PHP Tutorial PHPThumb image processing example_PHP tutorial

PHPThumb image processing example_PHP tutorial

Jul 13, 2016 am 10:30 AM
Image processing

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.

Usage demonstration:

Copy code The code is as follows:

//Load class library file
require_once 'path /to/ThumbLib.inc.php';

//Instantiate the class library, the address of the image you want to process can be a network address or a local address
$thumb = PhpThumbFactory::create('http://www.jb51.net /');

//Reduce the image proportionally to the maximum width of 100px or up to 100px. When only one parameter is entered, it is the widest size limit.
$thumb->resize(100, 100);

//Reduce the image to the original percentage, for example, 50 is 50% of the original.
$thumb->resizePercent(50);

//Intercept a 175px * 175px picture. Note that this is an interception, and the excess part is directly cropped, not forced to change the size.
$thumb->adaptiveResize(175, 175);

//Calculate from the center of the image and intercept the 200px * 100px image.
$thumb->cropFromCenter(200, 100);

//Screenshot, the first two parameters are the coordinates X and Y of the upper right corner of the picture to be solved. The next two parameters are the width and height of the image that needs to be solved.
$thumb->crop(100, 100, 300, 200);

//Reverse the image 180 degrees clockwise
$thumb->rotateImageNDegrees(180);

//Save (generate) the image, you can save it in other formats, please refer to the document for details
$thumb->save( 'NewPath/Of/image.jpg ' );

This class library has more functions, so I won’t introduce them in detail. If you also need to process images when developing a PHP website, you may wish to read the documentation of this class library to ensure that it is very simple for you to process images, and you no longer have to deal with images. Dealing with those dozen annoying php image processing functions!


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 images in GIF format to PNG format). Its special features also include color, special effects, etc.
Official website: http: //phpthumb.sourceforge.net/

Generally you only need the following file:
[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]

In fact, the function of phpThumb is more powerful than I originally thought. Here are some other useful parameters List it out:
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 equally according to the w parameter)
q: output if It is in JPG format, and its output quality can be specified
bg: background during output (if needed)
sw, sh, sx, sy: partial output, width, height, starting position
f: output Format, can be 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, Borders, masking, color adjustments, etc.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/764625.htmlTechArticleDownload address (github.com/masterexploder/PHPThumb). Note that this class library has an identical name called phpThumb, the only difference is in upper and lower case, so be careful when searching for documentation. On the Internet...
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Using Imgscalr for image processing in Java API development Using Imgscalr for image processing in Java API development Jun 18, 2023 am 08:40 AM

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 Golang image processing: how to perform color gradient and grayscale mapping of images Aug 19, 2023 am 08:53 AM

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

How to use Golang to enhance borders and edges of images How to use Golang to enhance borders and edges of images Aug 18, 2023 pm 09:46 PM

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

Laravel development advice: How to optimize image processing and caching Laravel development advice: How to optimize image processing and caching Nov 22, 2023 am 09:17 AM

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 add noise to pictures using Python How to add noise to pictures using Python Aug 19, 2023 am 11:21 AM

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,

How to use Golang to mask and mask effects on pictures How to use Golang to mask and mask effects on pictures Aug 27, 2023 am 09:07 AM

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 handle image caching and preloading in Vue? How to handle image caching and preloading in Vue? Aug 25, 2023 pm 04:21 PM

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 blur an image using PHP How to blur an image using PHP Aug 18, 2023 pm 02:13 PM

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

See all articles