Home  >  Article  >  Backend Development  >  PHPThumb image processing class example

PHPThumb image processing class example

WBOY
WBOYOriginal
2016-07-25 08:53:25966browse
  1. function about_phpthumb(){

  2. require_once './js/phpthumb/ThumbLib.inc.php';

  3. //instantiation Class library, the address of the image you want to process can be a network address or a local address

  4. $thumb = PhpThumbFactory::create('./images/cake.png');

  5. < p>//Reduce the image to a maximum width of 100px or a maximum of 100px. When only one parameter is entered, it is the widest size limit.
  6. $thumb->resize(100, 100);
  7. //$thumb->show();

  8. //Reduce the image to the original percentage, such as 50 50% of the original.

  9. $thumb->resizePercent(50);
  10. //$thumb->show();

  11. //Intercept a 175px * 175px picture. Note that this is an interception, beyond Parts are directly cropped, rather than forced to change size.

  12. $thumb->adaptiveResize(175, 175);
  13. //$thumb->show();

  14. //Calculate from the center of the image and intercept the 200px * 100px image.

  15. $thumb->cropFromCenter(200, 100);
  16. //$thumb->show();

  17. //Screenshot, the first two parameters are the pictures that need to be solved. The coordinates X, Y of the upper right corner. The last two parameters are the width and height of the image that need to be solved.

  18. $thumb->crop(100, 100, 300, 200);
  19. //$thumb->show();

  20. //Reverse the picture 180 degrees clockwise

  21. $thumb->rotateImageNDegrees(180);
  22. //$thumb->show();

  23. try{

  24. $thumb = PhpThumbFactory::create('./images/girl. png');
  25. }
  26. catch(Exception $e){
  27. throw $e;
  28. }

  29. $thumb->crop(100, 100, 300, 200);

  30. // $thumb->show();

  31. $thumb->cropFromCenter(200, 100);

  32. //$thumb->show();

  33. < ;p>$thumb->adaptiveResize(250, 250)->createReflection(40, 80, 80, true, '#a4a4a4'); //Reflection (reflection), the color is the border color of the original image
  34. // $thumb->show();

  35. $thumb->rotateImage('CW');

  36. //$thumb->show();

  37. < ;p>$thumb->adaptiveResize(300, 300);
  38. $thumb->save('./images/girl2.jpg','jpg'); //Save the image, the first parameter is after saving The name of the image, the second parameter is the conversion format of the image

  39. $thumb->resize(150,200)->cropFromCenter(100)->show(); //Chain lock Function

  40. }

Copy the code

Attached, the download address of the phpthumb image processing library: https://github.com/masterexploder/PHPThumb



Statement:
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