[PHP] Processing images

Source: Internet
Author: User

<?php/* processing image *//*  {PHP5} The processing of dynamic images is easier. In PHP.ini, the GD expansion pack is included and the annotations are removed.  Extension=php_gd2.dll contains some useful JPG features that support true color image processing.   General generated graphics, stored in PHP document format; However, you can get the dynamic graphics directly by using the HTML image insertion method src. Example: captcha/watermark/thumbnail ...     *  *//* {Create image} General process: 1. Set the header. (Tell the browser what type of mime you want to build) 2. Create {image Area}, after which the operation is based on this image area. * Imagecreatetruecolor generally add the @ symbol to avoid errors. * The return value is a resource handle is not populated when the background is black (default). * Imagecreate  3. {Image Area}, draw the fill background. First, you have a {color filler}imagecolorallocate--Assign a color imagecolorallocatealpha to an image--assign color + alpha to an image and then Fill the entire image background Imagefill--area image fill Imagefilledarc--Draw an elliptical arc and fill the imagefilledellipse--Draw an ellipse and fill the Imagefilledpolygon-- Draw a polygon and fill the imagefilledrectangle-draw a rectangle and fill 4. Draws the {graphic outline input text}5 on {background}. Outputs the final image. 6. Clears all resources. 7. Other pages call the image. Generally generated images can be PNG, JPG, GIF, bmp,jpeg, Wbmpheader ("content-type:text/html");//General page type is text/html, default does not write       * */?>

  

<?php header ("Content-type:image/png");//Set  header specifies the  MIME type $im=imagecreatetruecolor (200, 200);//Create a blank Image Area/* Set a color with it to fill the background of the image area */$blue =imagecolorallocate ($im, 0, 102, 255) Imagefill ($im, 0, 0, $blue);/* Draw text on image outline *///white text  Word//White $white=imagecolorallocate ($im, 255, 255, 255);//Draw two diagonal imageline ($im, 0, 0, N,, $white); Imageline ($im, 200, 0, 0, $white), Imagestring ($im, 5, Mr.Lee, $white);/* Outputs  the final image */imagepng ($IM);/* Clears all Resource usage */imagedestro Y ($im);//The image created by this page can be called by other pages?>

  

<?phpheader ("Content-type:image/png");/* Generates a random number string */$nmsg = ""; for ($i =0; $i < 4; $i + +) {//4-bit random number $nmsg.=dechex ( Rand (0,15));} echo $nmsg;//Prepare Image $im=imagecreatetruecolor (75,25);//general, a number high 25$blue=imagecolorallocate ($im, 0, 102, 255); $white = Imagecolorallocate ($im, 255, 255, 255);//Fill the image content Imagefill ($im, 0, 0, $white), Imagestring ($im, 5,, 4, $nmsg, $blue);/* Output Images and destroy the resources used */imagepng ($IM); Imagedestroy ($im);? >

  

<?phpheader ("content-type:image/jpg");/* Add a watermark to the image */$im =imagecreatefromjpeg ("2.jpg"); $white = Imagecolorallocate ($im, 255, 255, 255); Imagestring ($im, 5, ten, "This is a picture!", $white);//Imagettftext ($im,, 0, Ten, $white, "Simsun.ttf", "Sun is Chinese"), imagejpeg ($im); Imagedestroy ($im);? >

  

<?phpob_clean ();//If the output image is not displayed, then clear the output buffer header ("content-type:image/png"); $im =imagecreatetruecolor (200, 200) ; $white =imagecolorallocate ($im, 255, 255, 255); $blue =imagecolorallocate ($im, 0, 102, 255); Imagefill ($im, 0, 0, $blue); /$text =iconv ("GBK", "Utf-8", "鎷 Corporation 柉 fermium Archives 鏋 list vertical ã?"); $font = "C:\\windows\\fonts\\consola.ttf"; Imagettftext ($im, $white, $font, "Hello");/* Fourth fifth argument here, Used to display the position, be careful not to use 0, otherwise cannot find the output text content */imagestring ($im, 0, 5, "This is a boy.", $white); Imagepng ($im); Imagedestroy ($im);? >

  

<?phpob_clean ();//If the output image is not displayed, then clear the output buffer header ("content-type:image/png"); $im =imagecreatetruecolor (200, 200) ; $white =imagecolorallocate ($im, 255, 255, 255); $blue =imagecolorallocate ($im, 0, 102, 255); Imagefill ($im, 0, 0, $blue); /$text =iconv ("GBK", "Utf-8", "鎷 Corporation 柉 fermium Archives 鏋 list vertical ã?"); $font = "C:\\WINDOWS\\FONTS\\SIMSUN.TTC"; Imagettftext ($im, $white, $font, "Hello");/* Imagettftext ($ Image, $size, $angle, $x, $y, $color, $fontfile, $text) *//* here the fourth $x fifth $y parameter, used to display the position, note not to use 0, otherwise cannot find the output text content */imagestring ($im  , 0, 5, "This was a boy.", $white); $text = "It is in Chinese";//$text =iconv ("Utf-8", "Utf-8", "It is noon"); Imagettftext ($im, 25, 0, 20, $white, $font, $text);/* The output of this Chinese is correct. {Now the file encoding is utf8,html embedded file output text encoding is UTF8} */imagepng ($im); Imagedestroy ($im);? >

  

<?php/* Talk about how to use Eclipse *//*  * First is the interface: the useful is the editor section and the project manager (others are closed) *  * Second: Problems with the new project. * First of all, it's best to put the workspace in your folder root directory; As soon as you set the project name for each new project, the EPP automatically generates the folder. * * * * *  *///will practice thumbnail//echo __dir__;list ($w, $h) =getimagesize ("2.jpg"), $NW = $w *0.7; $nh = $h *0.7; $im _src= Imagecreatefromjpeg ("2.jpg"); $im =imagecreatetruecolor ($NW, $NH); imagecopyresampled ($im, $im _src, 0, 0, 0, 0, $NW, $NH, $w, $h); Ob_clean (); Header ("Content-type:image/png"); Imagepng ($im);//Imagepng ($im _src); Imagedestroy ($im); Imagedestroy ($im _src);? >

  

[PHP] Processing images

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.