This article mainly and you introduced the PHP based on the implementation of the GD library image thumbnail function, involving PHP for picture attributes related operation skills, the need for friends can refer to, hope to help everyone.
<?php/** * Generate thumbnail function (supports picture format: GIF, JPEG, PNG and BMP) * @author ruxing.li * @param string $src source picture path * @param int $width thumbnail width degree (equal to scale only when the height is specified) * @param int $width thumbnail height (equal to zoom only when width is specified) * @param string $filename save path (output to browser if not specified) * @return bool */fu Nction Mkthumbnail ($src, $width = null, $height = NULL, $filename = null) {if (!isset ($width) &&!isset ($height) ) return false; if (Isset ($width) && $width <= 0) return false; if (Isset ($height) && $height <= 0) return false; $size = getimagesize ($SRC); if (! $size) return false; List ($src _w, $src _h, $src _type) = $size; $SRC _mime = $size [' MIME ']; Switch ($src _type) {Case 1: $img _type = ' gif '; Break Case 2: $img _type = ' jpeg '; Break Case 3: $img _type = ' png '; Break Case: $img _type = ' wbmp '; Break Default:return false; if (!isset ($width)) $width = $src _w * ($height/$src _h); if (!isset ($height)) $height = $src _h * ($width/$src _w); $imagecreatefunc = ' Imagecreatefrom '. $img _type; $src _img = $imagecreatefunc ($SRC); $dest _img = Imagecreatetruecolor ($width, $height); Imagecopyresampled ($dest _img, $src _img, 0, 0, 0, 0, $width, $height, $src _w, $src _h); $imagefunc = ' image '. $img _type; if ($filename) {$imagefunc ($dest _img, $filename); } else {header (' Content-type: '. $src _mime); $imagefunc ($dest _img); } Imagedestroy ($src _img); Imagedestroy ($dest _img); return true;} $result = Mkthumbnail ('./img_3324.jpg ', 147, 147);
Note: Remember to open the support of GD library first