PHP Custom size icon Processing class sharing

Source: Internet
Author: User
Tags imagejpeg transparent color
PHP Custom size icon processing class sharing. This article mainly shared a key to generate a variety of size icon PHP script (example), for everyone to reference. We hope to help you.

Examples are as follows:

<?php/** * @name thumb thumbnail function * @param sting $img _name picture path * @param int $max _width sketch maximum width * @param int $max _ Height sketch max. * @param sting $suffix sketch suffix (e.g. "img_x.jpg" for small plots, "img_m.jpg" for the Middle, "img_l.jpg" for larger) * @return void */function   Thumb ($img _name, $max _width, $max _height, $path, $new _name) {$img _infos = getimagesize ($img _name); $img _height = $img _infos[0];//picture high $img _width = $img _infos[1];    Picture width $img _extension = ";       Picture suffix switch ($img _infos[2]) {Case 1: $img _extension = ' gif ';     Break       Case 2: $img _extension = ' jpeg ';     Break       Case 3: $img _extension = ' png ';     Break       Default: $img _extension = ' jpeg ';   Break   } $new _img_size = Array ();   $new _img_size[' width ' = $max _width;      $new _img_size[' height '] = $max _height;   $img _func = ";  function name $img _handle = "; Picture handle $thum _handle = ";   Thumbnail picture handle switch ($img _extension) {case ' jpg ': $img _handle = imagecreatefromjpeg ($img _name);    $img _func = ' imagejpeg ';     Break       Case ' JPEG ': $img _handle = imagecreatefromjpeg ($img _name);       $img _func = ' imagejpeg ';     Break       Case ' png ': $img _handle = imagecreatefrompng ($img _name);       Imagesavealpha ($img _handle, true);       $img _func = ' imagepng ';     Break       Case ' gif ': $img _handle = imagecreatefromgif ($img _name);       $img _func = ' imagegif ';     Break       Default: $img _handle = imagecreatefromjpeg ($img _name);       $img _func = ' imagejpeg ';   Break   } $quality = 100;//picture quality if ($img _func = = ' Imagepng ') {$quality = 9;   } $thum _handle = Imagecreatetruecolor ($new _img_size[' height '], $new _img_size[' width ');   Imagealphablending ($thum _handle,false);//This is important, meaning that the color is not merged, directly replaced with $img image color, including transparent color;    Imagesavealpha ($thum _handle,true);//Here is very important, meaning not to lose the transparent color of $thumb image; if (function_exists (' imagecopyresampled ')) {imagecopyresampled ($thum _handle, $img _handle, 0, 0, 0, 0, $new _img_size[' H Eight '], $new _img_size[' width '],$Img_height, $img _width); } else {imagecopyresized ($thum _handle, $img _handle, 0, 0, 0, 0, $new _img_size[' height '], $new _img_size[' width '), $i   Mg_height, $img _width); } call_user_func_array ($img _func,array ($thum _handle, $path. '   /'. $new _name, $quality));     Imagedestroy ($thum _handle);//clear handle Imagedestroy ($img _handle);//Clear handle} $IconArray = Array ("IOS8" + = Array ( Array ("width" = +, "height" = +, "path" = "iOS8", "name" = "Icon-180.png"), Array ("width" = 1 "Height" = +, "path" = "iOS8", "name" = "Icon-120.png"), Array ("width", "height" = 152, "Path" and "iOS8", "Name" and "Icon-152.png"), Array ("width" and "height" = "," "path" = "iOS8", " Name "=" and "Icon-76.png"), Array ("width" = 144, "height" = = 144, "path" = "iOS8", "Name" and "Icon-144.png" ), Array ("width" = +, "height" = +, "path" = "iOS8", "name" = "Icon-72.png"), Array ("width" =& Gt 114, "height" = +, "path" = "iOS8", "name" = "Icon-114.png"), Array ("width" = "*", "height" = 57, "Path" = "iOS8", "name" = "Icon-57.png"), Array ("width" = "+", "height" = +, "path" = "iOS8", "N Ame "+" ("Icon-100.png"), Array ("width" = +, "height" = +, "path" = "iOS8", "name" = "Icon-50.png" ), Array ("width" = +, "height" =, "path" = "iOS8", "name" = "Icon-80.png"), Array ("width" = >, "height" = +, "path" = "iOS8", "name" = "Icon-40.png"), Array ("width" = +, "height" =&gt ; , "path" = "iOS8", "Name" and "Icon-58.png"), Array ("width" and "height" = +, "path" = "iOS8" "," name "=" Icon-29.png ")," IOS "= = Array (" width "=" + "," height "= +)," path "= "ios", "name" and "Icon-60@3x.png"), Array ("width" = +, "height" = +, "path" = "ios", "name" and "="     Icon-60@2x.png "),Array ("width", "height", "path" = "ios", "name" = "Icon-76@2x.png"), Array ("width" = 76  , "height" = +, "path" = "ios", "name" = "Icon-76.png"), Array ("width" = 144, "height" = 144,    "Path", "ios", "name" and "Icon-72@2x.png", Array ("width" = "height" = "," "path" = "ios", "Name" = "Icon-72.png"), Array ("width" = +, "height" = "," "path" = "ios", "name" = "icon-57@2x". PNG "), Array (" width "= +," height "and" * "," path "=" ios "," name "=" Icon-57.png "), Array (" Widt H "= +," "height" = +, "path" = "ios", "name" = "Icon-50@2x.png"), Array ("width" = "+", "Height "+," "Path" = "ios", "name" = "Icon-50.png"), Array ("width" = "height" = "*", "path" =& gt; " iOS "," name "=" Icon-40@2x.png "), Array (" width "= +," height "= +," path "=" ios "," name "=     "Icon-40.png"),Array ("width" = +, "height" = +, "path" = "ios", "name" = "Icon-29@2x.png"), Array ("width" = "Height" and "path" = "ios", "name" = "Icon-29.png"), "ANDROID" = = Array (" Width "= 144," height "= 144," path "=" android/drawable "," name "=" Icon.png "), Array (" width "= > 144, "height" = 144, "path" = "android/drawable-xhdpi", "name" = "Icon.png"), Array ("width" = 72 , "height" =, "path" = "android/drawable-hdpi", "name" = "Icon.png"), Array ("width" = "hei" Ght "=", "path" = "android/drawable-mdpi", "name" = "Icon.png"), Array ("width" = +, "height" =&G T   "Path" = "android/drawable-ldpi", "name" = "Icon.png")); foreach ($IconArray ["IOS8"] as $key = + $IconType) {thumb ("icon.png", $IconType [' width '], $IconType [' Height '],$ icontype[' path '], $IconType [' name ']); } foreach ($IconArray ["IOS"] as $key = $IconType) {Thumb ("icon.png", $IconType [' width '], $IconType [' height '], $IconType [' Path '], $IconType [' name ']);} foreach ($IconArray ["ANDROID"] as $key = + $IconType) {thumb ("icon.png", $IconType [' width '], $IconType [' Height '],$ icontype[' path '], $IconType [' name ']); }?>

Related recommendations:

Very strong PHP image processing class

How to implement PHP thumbnail image

PPT Picture Transparency Add transparency gradient effect to PHP picture

Related Article

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.