An in-depth discussion on the implementation of PHP generated thumbnails _php tutorial

Source: Internet
Author: User
We are using

PHP generates thumbnail HTML code

  1. < ! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en">
  2. < HTML>
  3. < HEAD>
  4. < TITLE> upload images < /title >
  5. < META NAME="Generator" CONTENT ="editplus">
  6. < META NAME = "Author" CONTENT = "" >
  7. < META NAME="Keywords" CONTENT ="">
  8. < META NAME = "Description" CONTENT = "">
  9. < meta http-equiv="Content-type" content = "text/html; CHARSET=GBK " />
  10. < /head >
  11. < BODY>
  12. < FORM METHOD="POST" ACTION ="tu.php?act=upload" enctype="multipart/ Form-data " >
  13. < p > < INPUT type = "file" name = "file" /> < /P ;
  14. < p > < INPUT type = "submit" value = "Hao" /> < INPUT type = "reset" /> < /P ;
  15. < /form >
  16. < /body >
  17. < /html >


PHP generates thumbnail PHP code

 
 
  1. < ? PHP
  2. /* Background Login interface
  3. * Huang Chunlong Learn to write
  4. * First Write Time: 2009-10-27
  5. * Update Time: 2009/11/24
  6. */
  7. Require_once '. /xmphp/init.php ';
  8. Full Station configuration file
  9. Require_once Xmphp_common. ' /smarty.php ';
  10. Smarty function
  11. Require_once Xmphp_common. ' /mysql.php ';
  12. MySQL Features
  13. Require_once Xmphp_common. ' /func.php ';
  14. Common functions
  15. if (Isset ($_get[' act ') &&$_get[' act ']
    = = ' upload ') {
  16. $ file =$_files[' file ';
  17. $ Info = PathInfo ($file [' name ']);
  18. $ a = Array (' jpg ', ' gif ', ' PNG ');
  19. if (!in_array ($info [' extension '], $a)) {
  20. Alert ("Please select a picture in jpg,gif,png format
    Upload ");
  21. Exit
  22. }
  23. if ($file [' name ']! = ') {
  24. $ dirname = Date (' Ym ');
  25. $ dirname = '.. /upload/'. $dirname;
  26. Original path
  27. $ Xin = $dirname. ' /s ';//php generate thumbnail path
  28. if (!file_exists ($xin)) {
  29. @mkdir ($xin);
  30. }
  31. $ Image1 = $info [' filename ']. ' 120_120 '. '. '
    . $info [' extension '];//thumbnail name
  32. $ Image2 = $info [' filename ']. ' 300_300 '. '. '
    . $info [' extension '];//thumbnail name
  33. List ($IMAGW, $imagh) =getimagesize ($file
    [' Tmp_name ']); /Get the width height of the original image (another $file
    [' Tmp_name '] is just a temporary file path that may sometimes
    will be error, such as error only need to change the temporary file path to your upload
    After the path of the original image)
  34. 120 figure judging various situations to obtain the width of the thumbnail image
  35. if ($IMAGW< =120&& $imagh< =120) {
  36. $ m120w = $IMAGW;
  37. $ m120h = $imagh;
  38. }elseif ($IMAGW>$imagh)
  39. {
  40. $ m120w = 120;
  41. $ m120h = intval ($m 120w/number_format (
    $IMAGW/$imagh, 2));//The width of the thumbnail divided by (original
    The width of the graph divided by the height of the original) Number_format Handbook
  42. }
  43. Else
  44. {
  45. $ m120h = - ;
  46. $ m120w = intval ($m 120h/number_format (
    $imagh/$IMAGW, 2));//The height of the thumbnail divided by the original image
    Height divided by the width of the original) Number_format search manual
  47. }
  48. 300 figure judging various situations to obtain the width of the thumbnail image
  49. if ($IMAGW< =300&& $imagh< =300) {
  50. $ m300w = $IMAGW;
  51. $ m300h = $imagh;
  52. }elseif ($IMAGW>$imagh) {
  53. $ m300w = 300;
  54. $ m300h = intval ($m 300w/number_format (
    $IMAGW/$imagh, 2));//The width of the thumbnail divided by (original
    The width of the graph divided by the height of the original) Number_format Handbook
  55. }else{
  56. $ m300h = 300;
  57. $ m300w = intval ($m 300h/number_format (
    $imagh/$IMAGW, 2));//The High divide of the thumbnail (original
    The height of the graph divided by the width of the original) Number_format Handbook
  58. }
  59. if ($info [' extension ']== ' jpg ') {
  60. $info [' extension ']= ' jpeg ';//judging the image class
    If the type is JPG, convert it to JPEG because the image
    The function is JPEG rather than JPG when working with JPG.
  61. }
  62. $ IML = ' Imagecreatefrom ' . $info [' extension '];
  63. Get different functions for different picture formats
  64. $ Yuan = $IML ($file [' tmp_name ']);
  65. Identification of the original image based on the different functions previously taken
  66. $ MU1 = Imagecreatetruecolor ($m 120w, $m 120h);
  67. The identity of the thumbnail to be generated
  68. $ MU2 = Imagecreatetruecolor ($m 300w, $m 300h);
  69. The identity of the thumbnail to be generated
  70. $ C = ' image ' . $info [' extension '];
  71. Generate output thumbnail function, cannot write separately, otherwise error
  72. Imagecopyresampled ($mu 1, $yuan, 0,0,0,
    0, $m 120w, $m 120h, $IMAGW, $imagh);//Generate thumbnails 120
  73. $ Res = $c ($mu 1, $xin. ' /'. $image 1);
  74. Store thumbnail images
  75. if (! $res) {
  76. Alert (' Generate 120 thumbnails failed ');
  77. Exit
  78. }
  79. Imagecopyresampled ($mu 2, $yuan, 0,0
    , 0,0, $m 300w, $m 300h, $IMAGW, $imagh);
  80. PHP generated thumbnail generated thumbnail image 120
  81. $ Res = $c ($mu 2, $xin. ' /'. $image 2);
  82. Store thumbnail images
  83. if ($res) {
  84. Alert (' Generate 300 thumbnail success ');
  85. Exit
  86. }
  87. }
  88. }
  89. $TPL- > display ("tu/tu.html");
  90. ?>

The above section of the code example is the implementation of the PHP generated thumbnails related methods.


http://www.bkjia.com/PHPjc/446079.html www.bkjia.com true http://www.bkjia.com/PHPjc/446079.html techarticle we are using PHP to generate thumbnail HTML code! Doctypehtmlpublic "-//w3c//dtdhtml4.0transitional//en" > HTML > HEAD > TITLE > Uploading Images/title > META NAME = "Ge Nerator "CONTENT = ...

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