Php Image Processing

Source: Internet
Author: User
Tags unsupported
This time is so impetuous that I don't know where to start. If you want to learn this, you feel that you are missing it. If you want to learn this, you need to use it now. I don't know whether to go to the left or right, even though they can all go to the destination. This is an image processing note. It's just my personal notes. I haven't studied it carefully, and there is a small mistake. 1? Php2header (content-type: texthtml;

This time is so impetuous that I don't know where to start. If you want to learn this, you feel that you are missing it. If you want to learn this, you need to use it now. I don't know whether to go to the left or right, even though they can all go to the destination. This is an image processing note. It's just my personal notes. I haven't studied it carefully, and there is a small mistake. 1? Php 2 header ("content-type: text/html;

This time is so impetuous that I don't know where to start. If you want to learn this, you feel that you are missing it. If you want to learn this, you need to use it now. I don't know whether to go to the left or right, even though they can all go to the destination.

This is an image processing note. It's just my personal notes. I haven't studied it carefully, and there is a small mistake.

1
 {$ Info}

"; 11} 12 if (is_array ($ content )&&! Empty ($ content) 13 {14 foreach ($ content as $ key => $ row) 15 {16 $ I = $ key + 1; 17 $ html. ="

\ T {$ I }:\ t {$ row}

"; 18} 19} 20 if ($ tip) 21 {22 $ html. ="

\ TTIP: {$ tip}

"; 23} 24 $ html. ="
"; 25 echo $ html; 26} 27/** 28 * generate a thumbnail 29 * @ param $ src_img action image file name 30 * @ param $ new_img new image file name 31 * @ param $ n_w width 32 * @ param $ n_h height 33 * @ return resouce 34 * @ author cntnn11 35 * @ date 2013-03-10 36 */37 function thumb ($ src_img, $ new_img, $ n_w = 0, $ n_h = 0) 38 {39 if (is_file ($ src_img) 40 {41 list ($ s_w, $ w_h, $ s_t) = getimagesize ($ src_img); 42 43 // proportional scaling limit on the width and height of the source image, use a fixed formula 44 // scale the largest edge of the original image as the maximum size of the new image, and the other side scales proportionally by the following formula 45 // If the width of the original image is less than the height, then recalculate the width of the New Graph. Otherwise, recalculate the height of the New Graph 46 if ($ n_w & ($ s_w <$ s_h )) 47 {48 $ n_w = ($ n_h/$ s_h) * $ s_h; 49} 50 else 51 {52 $ n_h = ($ n_w/$ s_w) * $ s_w; 53} 54 55 // start to generate 56 $ res_img_new = imagecreatetruecolor ($ n_w, $ n_h); 57 switch ($ s_t) 58 {59 case 1: 60 $ res_img = imagecreatefromgif ($ src_img); 61 $ ext = 'gif'; 62 break; 63 case 2: 64 $ res_img = imagecreatefromjpeg ($ src_img ); 65 $ ext = 'jpg '; 66 break; 67 case 3: 68 $ res_img = imagecreatefrompng ($ src_img); 69 $ ext = 'png'; 70 break; 71 default: 72 echo 'unsupported image type'; 73 return false; 74 break; 75} 76 77 imagecopyresampled ($ res_img_new, $ res_img, 0, 0, 0, 0, $ n_w, $ n_h, $ s_w, $ s_h); 78 // $ res_img_new = imagecreate ($ n_w, $ n_h); 79 // imagecopyresized ($ res_img_new, $ res_img, 0, 0, 0, 0, 0, $ n_w, $ n_h, $ s_w, $ s_h); 80 global $ img_new_dir; 81 $ new_img_file = $ img_new_dir. $ new_img. '. '. $ ext; 82 imagejpeg ($ res_img_new, $ new_img_file); 83 // genImage ($ res_img_new, $ new_img_file, $ s_t); 84 imagedestroy ($ res_img ); 85 imagedestroy ($ res_img_new); 86 echo 'scaled image: '; 87 echo' $ new_img_file. '"alt =" generated thumbnail ">
'; 88} 89} 90/** 91 * receive input parameters to generate an image 92 * @ param $ img_res processed image resource 93 * @ param $ img_file the new image address 94 * @ param $ img_type: Image Type 95 * @ return resouce 96 * @ author cntnn11 97 * @ date 2013-03-10 98 */99 function genImage ($ img_res, $ img_file, $ img_type = 2) 100 {101 switch ($ img_type) 102 {103 case return imagegif ($ img_res, $ img_file); 105 break; 106 case return imagejpeg ($ img_res, $ img_file); 108 break; 109 case return imagepng ($ img_res, $ img_file); 111 break; 112 default: 113 return 'unsupported image type'; 114 break; 115} 116} 117 118/* ================================== ========================================================== ========================================================== ================= */119 global $ img_name, $ img_new_dir; 120 $ img_name = 'testimg.jpg '; 121 $ img_new_dir = 'genimages/'; 122 123 echo"

Original Test image: '{$ img_name }'

"; 124 echo '$ img_name. '"alt =" test image "width =" 200px ">'; 125 126 127 // obtain image resources. Use jpg format for testing image 128 $ img_sour = imagecreatefrom#('testimg.jpg '); 129 130 // obtain the image width and height 131 $ title = "retrieve the image width and height"; 132 $ info = "function imagesx (img source) imagesy (img source) involved )"; 133 $ content = array (134 'imagesx (image): input an image resource type created using the imagecreate _ () function as the parameter. The return width is ', 135' imagesy (image ): same as imagesx, return height! ', 136' original width of the test image :'. imagesx ($ img_sour ). 'px original height :'. imagesy ($ img_sour ). 'px ', 137); 138 $ tip = "the parameters of these two functions must be of the image resource type !! & Quot; 139 echoHtml ($ title, $ info, $ content, $ tip ); 140 141 // another method for obtaining image attributes 142 $ title = "use getimagesize (image name); get image attributes "; 143 $ info = "This function returns an array containing the width, height, and image type information! You only need to receive a file name! "; 144 $ content = array (145 'usage: getimagesize ('. $ img_name. ')', 146 'returns an array: subscript 0 indicates the width, subscript 1 indicates the height, subscript 2 indicates the image type, and 147' indicates the image type. 1 = GIF, 2 = JPG, 3 = PNG, 4 = SWF, 5 = PSD, 6 = BMP, 7 = TIFF (intel byte order), 8 = TIFF (motorola byte order ), 9 = JPC, 10 = JP2, 11 = JPX, 12 = JB2, 13 = SWC, 14 = IFF, 15 = WBMP, 16 = XBM ', 148 'subscripts starting from 3 are of the text type, which can be used to describe the values 0, 1, and 2 ', 149); 150 echoHtml ($ title, $ info, $ content, $ tip); 151 152 // image scaling function 153 $ Title = "image scaling, use the imagecopyresampled () function with better results"; 154 $ info = "mainly learns proportional scaling because width and height are not restricted, then the new image will be deformed "; 155 $ content = array (156 'imagecopyresampled (dst_image, src_image, dst_x, dst_y, src_x, src_y, dst_w, dst_h, src_w, src_h) ', 157' parameter description: ', 158' dst_image [New Image] image resource type ', 159' src_image [original image to be scaled down] image resource type ', 160' dst_x, dst_y, dst_w, dst_h [x-axis start point, Y-axis start point, width and height of the thumbnail] numerical type ', 161' src_x, src_y, src_w, src_h [x-axis start point of the original image, Y axis start point, width, and height Value Type ', 162); 163 $ tip = "there is also an imagecopyresized () function. The parameters are the same as those of the imagecopyresampled () function, but the effect is not good. Why? "; 164 echoHtml ($ title, $ info, $ content, $ tip); 165 166 // test the scaling method 167 $ title = 'Write a thumb () method, used to scale down an image. 168 $ info = 'Use the imagecopyresampled () function to use'; 169 $ content = array (170 'first determine the parameter: original image, the target position, width and height of the thumbnail, and 171 are used to obtain the image attributes, width and height, and type to create corresponding image resources ', 172 'use the fixed formula to calculate the width and height of the new image proportional scaling ', 173 'generate new thumbnail slices Based on the image type', 174 'release image resource', 175 ); 176 $ tip = "A black image is generated. You need to solve this problem !!!!!!!!!!! "; 177 echoHtml ($ titl, $ info, $ content, $ tip); 178 thumb ($ img_name, 'suolve1', 500,500 ); 179 180 // image transparency 181/* imagecolortransparent () 182 imagecolorstotal () 183 imagecolorsforindex () 184 imagecolorallocate () 185 imagefill () */186 187 imagedestroy ($ img_sour );

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.