您现在的位置是:网站首页 > 脚本编程>
php 生成缩略图解决方法
简介
参数说明:mkThumbnail(图片的路径,宽度,高度,名称),本函数返回的是一个缩略图的名称。具体事宜请与您实际相结合。注意:记得开启GD图形库扩展
<?php
function mkThumbnail($src, $width = null, $height = null, $filename = null) {
if (...
参数说明:mkThumbnail(图片的路径,宽度,高度,名称),本函数返回的是一个缩略图的名称。具体事宜请与您实际相结合。注意:记得开启GD图形库扩展
<?php function 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 15 : $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); $filename = time() . rand(1, 100) . "_thumb.jpg"; $res = imagejpeg($dest_img, './Uploads/photo/' . $filename, 100); imagedestroy($src_img); imagedestroy($dest_img); return $filename; } $result = mkThumbnail('./Uploads/photo/5600ba24d6bdf.jpg', 196); echo $result; ?>
打赏本站,你说多少就多少

本文地址:https://www.qi522.com/view/77.html
来 源:千奇博客