Brief analysis of PHP drawing technology

  • 2020-07-21 07:14:27
  • OfStack

1, picture format: at present, common picture formats for website development are gif,jpg/jpeg,png...
The difference between:
The & # 8226; gif has a high compression ratio, but can only display 256 colors, which may cause color loss and can display animations
The & # 8226; jpg/jpeg images have a high compression rate (lossless compression) and can be displayed in smaller files, but are more commonly used on web pages
The & # 8226; png combines the advantages of gif and jpg, with the disadvantage that animation cannot be displayed

2. Drawing through PHP programming


<?php
    // The drawing technology   Basic steps   The premise : in php.ini Enable in file gd library 
    // Create a canvas   The default background is black 
    $img=imagecreatetruecolor(400,300);
    // Draw all kinds of graphs 
    // create 1 A color 
    $background = imagecolorallocate($img, 255, 0, 0);
    // A circle 
    //imageellipse($img,30,30,50,50,$background);
    // The ellipse 
    //imageellipse($img,30,30,50,30,$background);
    // Draw a straight line 
    //imageline($img,0,0,400,300,$background);
    // Draw a rectangular 
    //imagerectangle ($img, 50 , 20 , 100 , 40 , $background);
    // Fill the rectangle 
    //imagefilledrectangle ($img, 50 , 20 , 100 , 40 , $background);
    // Draw arc 
    //imagearc($img, 100, 100, 150, 150, 180, 270, $background);
    // Draw a fan   IMG_ARC_CHORD A straight line connects the start and end points    IMG_ARC_PIE
    //imagefilledarc($img, 100, 100, 150, 150, 180, 270, $background,IMG_ARC_PIE);

    // Copy the picture to the canvas 
/*    $scrImg=imagecreatefromgif('http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif');
    $scrImgInfo=getimagesize('http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif');
    imagecopy ($img,$scrImg,10,10,0,0,$scrImgInfo[0],$scrImgInfo[1]);
*/
    //imagecopy ($img,$scrImg,10,10,0,0,270,129);

    // write 
    //imagestring ($img , 5 , 20 , 20 , "hello,world", $background );
    // Write in Chinese 
    $str="PHP Painting technology ";
    imagettftext ($img , 30 , 0 , 50 ,50, $background , "MSYHBD.TTF" , $str);
    // Output image to web page ( Or save it as )
    header("content-type: image/png");
    imagepng($img);
    // Destroy the image ( Free memory )
    imagedestroy($img);
?>


Related articles: