Phpthumb image Processing Class example

Source: Internet
Author: User
Tags border color
  1. function About_phpthumb () {

  2. Require_once './js/phpthumb/thumblib.inc.php ';

  3. Instantiate the class library, the address of the image you want to work with can be a network address, or it can be a local address

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

  5. Reduce the picture to a maximum width of 100px or up to 100px, when only one parameter is entered, the widest size is limited.

  6. $thumb->resize (100, 100);
  7. $thumb->show ();

  8. Reduce the picture to the original percentage, such as 50 is the original 50%.

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

  11. Intercept a 175px * 175px picture, note that this is the intercept, the part of the excess is cut off directly, is not forced to change the size.

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

  14. From the center of the image, capture 200px * 100px images.

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

  17. , the first two parameters are the coordinates x, y of the upper-right corner of the picture that needs to be solved. The following two parameters are required to solve the picture width, height.

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

  20. Invert the picture clockwise by 180 degrees.

  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. $thumb->adaptiveresize (+)->createreflection (+, +, +, true, ' #a4a4a4 '); Reflection (reflection), color is the border color of the original image

  34. $thumb->show ();

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

  36. $thumb->show ();

  37. $thumb->adaptiveresize (300, 300);

  38. $thumb->save ('./images/girl2.jpg ', ' jpg '); Save the picture, the first parameter is the name of the saved picture, the second parameter is the conversion format of the picture

  39. $thumb->resize (150,200)->cropfromcenter (+)->show (); Chain Lock Action

  40. }

Copy Code

Attached, phpthumb download the Image processing Class library address: Https://github.com/masterexploder/PHPThumb

  • 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.