PHP image Processing Function Example Summary, PHP picture function Instance Code

Source: Internet
Author: User
Tags imagecopy imagejpeg transparent color
    1. Imagecolorsforindex ()

    2. Imagecolorat ()
    3. Draw a graphic on the picture $img =imagecreatefromgif ("./images/map.gif");

    4. /**

    5. * Image Sharpening Processing
    6. * Edit by Bbs.it-home.org
    7. */
    8. $red = Imagecolorallocate ($img, 255, 0, 0);

    9. Imageline ($img, 0, 0, +, +, $red);

    10. Imageellipse ($img, $, $red);
    11. Imagegif ($img, "./images/map2.gif");
    12. Imagedestroy ($IMG);
Copy Code

Picture Normal Zoom

    1. function Thumn ($background, $width, $height, $newfile) {
    2. List ($s _w, $s _h) =getimagesize ($background);//Get original picture height, width
    3. if ($width && ($s _w < $s _h)) {
    4. $width = ($height/$s _h) * $s _w;
    5. } else {
    6. $height = ($width/$s _w) * $s _h;
    7. }
    8. $new =imagecreatetruecolor ($width, $height);
    9. $img =imagecreatefromjpeg ($background);
    10. Imagecopyresampled ($new, $img, 0, 0, 0, 0, $width, $height, $s _w, $s _h);
    11. Imagejpeg ($new, $newfile);
    12. Imagedestroy ($new);
    13. Imagedestroy ($IMG);
    14. }
    15. Thumn ("Images/hee.jpg", "A./images/hee3.jpg");
Copy Code

GIF Transparent Color processing

    1. /**

    2. * Picture Clipping processing
    3. * Edit by Bbs.it-home.org
    4. */

    5. function Cut ($background, $cut _x, $cut _y, $cut _width, $cut _height, $location) {

    6. $back =imagecreatefromjpeg ($background);
    7. $new =imagecreatetruecolor ($cut _width, $cut _height);
    8. Imagecopyresampled ($new, $back, 0, 0, $cut _x, $cut _y, $cut _width, $cut _height, $cut _width, $cut _height);
    9. Imagejpeg ($new, $location);
    10. Imagedestroy ($new);
    11. Imagedestroy ($back);
    12. }
    13. Cut ("./images/hee.jpg", the 117, the "./images/hee5.jpg");
    14. ?>

Copy Code

image watermark and watermark text

  1. /**

  2. *
  3. * Image Add text watermark
  4. */

  5. function Mark_text ($background, $text, $x, $y) {

  6. $back =imagecreatefromjpeg ($background);
  7. $color =imagecolorallocate ($back, 0, 255, 0);
  8. Imagettftext ($back, 0, $x, $y, $color, "Simkai.ttf", $text);
  9. Imagejpeg ($back, "./images/hee7.jpg");
  10. Imagedestroy ($back);
  11. }
  12. Mark_text ("./images/hee.jpg", "elaborating PHP", 150, 250);
  13. Image watermark
  14. function Mark_pic ($background, $waterpic, $x, $y) {
  15. $back =imagecreatefromjpeg ($background);
  16. $water =imagecreatefromgif ($waterpic);
  17. $w _w=imagesx ($water);
  18. $w _h=imagesy ($water);
  19. Imagecopy ($back, $water, $x, $y, 0, 0, $w _w, $w _h);
  20. Imagejpeg ($back, "./images/hee8.jpg");
  21. Imagedestroy ($back);
  22. Imagedestroy ($water);
  23. }
  24. Mark_pic ("./images/hee.jpg", "./images/gaolf.gif", 50, 200);

Copy Code

Picture Rotation

    1. /**

    2. * Picture rotation
    3. * Edit by Bbs.it-home.org
    4. */
    5. $back =imagecreatefromjpeg ("./images/hee.jpg");

    6. $new =imagerotate ($back, 45, 0);

    7. Imagejpeg ($new, "./images/hee9.jpg");
    8. ?>

Copy Code

Picture Horizontal Flip Vertical Flip

  1. /**

  2. * Picture Horizontal Flip Vertical Flip
  3. * Edit by Bbs.it-home.org
  4. */
  5. function turn_y ($background, $newfile) {

  6. $back =imagecreatefromjpeg ($background);

  7. $width =imagesx ($back);
  8. $height =imagesy ($back);
  9. $new =imagecreatetruecolor ($width, $height);
  10. for ($x =0; $x < $width; $x + +) {
  11. Imagecopy ($new, $back, $width-$x-1, 0, $x, 0, 1, $height);
  12. }
  13. Imagejpeg ($new, $newfile);
  14. Imagedestroy ($back);
  15. Imagedestroy ($new);
  16. }
  17. function turn_x ($background, $newfile) {
  18. $back =imagecreatefromjpeg ($background);
  19. $width =imagesx ($back);
  20. $height =imagesy ($back);
  21. $new =imagecreatetruecolor ($width, $height);
  22. for ($y =0; $y < $height; $y + +) {
  23. Imagecopy ($new, $back, 0, $height-$y-1, 0, $y, $width, 1);
  24. }
  25. Imagejpeg ($new, $newfile);
  26. Imagedestroy ($back);
  27. Imagedestroy ($new);
  28. }
  29. Turn_y ("./images/hee.jpg", "./images/hee11.jpg");
  30. Turn_x ("./images/hee.jpg", "./images/hee12.jpg");
  31. ?>

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