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