PHP uses the GD library for image watermarks and thumbnails-encapsulated into classes

Source: Internet
Author: User

After learning how to use the GD library to achieve the various processing of the picture, then we can find that no matter which method, there are similarities, if we put these similarities and not similar places are packaged into classes, so that can improve the speed of the code, and save a lot of time, no nonsense to say, bearer, on the code!

First, start by creating a PHP file: class.php (Custom)

We know that in

Add a text watermark to the original picture: http://www.cnblogs.com/finalanddistance/p/7243346.html

Add a picture watermark to the original picture: http://www.cnblogs.com/finalanddistance/p/7240465.html

To thumbnail the original image: Http://www.cnblogs.com/finalanddistance/p/7243346.html

, there are four steps: Open a picture, manipulate a picture, output a picture, destroy a picture

Which, the operation of opening pictures, outputting pictures, destroying pictures is the same, only in the operation of the picture will be different, then we began to object-oriented to encapsulate these into a method, easy to use

1, the similar operation is encapsulated

We can see that when the picture is opened, the first action is to configure the picture path, then we can encapsulate it as a constructor, so that each run must execute it;

  In the method, the place where we use the parameter is where the user can customize it at the time of invocation.

  When setting up a property that you want to use in other methods, turn it into a private property.

(1)

Open picture

(2) Output image

(3) Destroying images

2, the difference between the relevant operation

(1) Thumbnail image

Test (Create a new PHP file: test.php)

2.1 Code Section

Results

(2) Text watermark

Code section

Test

Results

Image watermark

Code

Test

Effect

That's all the content!

END

PHP uses the GD library for image watermarks and thumbnails-encapsulated into classes

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.