PHPThumb image processing example
-
Function about_phpthumb (){
- Require_once './js/phpthumb/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 ('./images/cake.png ');
-
// Scale down the image to a maximum width of PX or a maximum of px. when only one parameter is input, the maximum width is limited.
- $ Thumb-> resize (100,100 );
- // $ Thumb-> show ();
-
// Reduce the image proportional ratio to the original percentage. for example, 50 is the original 50%.
- $ Thumb-> resizePercent (50 );
- // $ Thumb-> show ();
-
// Intercept a 175px * 175px Image. Note that this is the intercept. the excess part is directly cropped, not forcibly changed.
- $ Thumb-> adaptiveResize (175,175 );
- // $ Thumb-> show ();
-
// Extract a PX * px image from the image center.
- $ Thumb-> cropFromCenter (200,100 );
- // $ Thumb-> show ();
-
// The first two parameters are the coordinates X and Y in the upper-right corner of the image to be extracted. The following two parameters are the width and height of the image to be solved.
- $ Thumb-> crop (100,100,300,200 );
- // $ Thumb-> show ();
-
// Reverse the image clockwise to 180 degrees
- $ Thumb-> rotateImageNDegrees (180 );
- // $ Thumb-> show ();
-
Try {
- $ Thumb = PhpThumbFactory: create ('./images/girl.png ');
- }
- Catch (Exception $ e ){
- Throw $ e;
- }
-
$ Thumb-> crop (100,100,300,200 );
- // $ Thumb-> show ();
-
$ Thumb-> cropFromCenter (200,100 );
- // $ Thumb-> show ();
-
$ Thumb-> adaptiveResize (250,250)-> createReflection (40, 80, 80, true, '# a4a4a4'); // reflection (reflection). The color is the border color of the source image.
- // $ Thumb-> show ();
-
$ Thumb-> rotateImage ('cw ');
- // $ Thumb-> show ();
-
$ Thumb-> adaptiveResize (300,300 );
- $ Thumb-> save ('. /images/girl2.jpg ', 'jpg'); // save the image. The first parameter is the name of the saved image, and the second parameter is the conversion format of the image.
-
$ Thumb-> resize (150,200)-> cropFromCenter (100)-> show (); // chain lock function
- }
Appendix, phpthumb image processing class library: https://github.com/masterexploder/PHPThumb |