生成PHP缩略图
来源:互联网 发布:淘宝怎么养小号 编辑:程序博客网 时间:2024/05/21 09:51
$data=M('drink_picture')->limit('1')->select();
$data=current($data);
$img=$data['pic_url'];
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);
$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($data['pic_url'], 120, 147);
$data=current($data);
$img=$data['pic_url'];
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);
$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($data['pic_url'], 120, 147);
阅读全文
0 0
- php生成缩略图
- PHP生成图片缩略图
- PHP生成图片缩略图
- PHP批量生成缩略图
- PHP批量生成缩略图
- PHP批量生成缩略图
- PHP图片生成缩略图
- PHP生成图片缩略图
- php 生成缩略图
- PHP 生成缩略图类
- PHP 生成图片缩略图
- php生成缩略图类
- 生成缩略图PHP
- PHP生成图片缩略图
- Php生成缩略图
- php生成缩略图
- PHP缩略图的生成
- PHP 生成图片缩略图
- 欢迎使用CSDN-markdown编辑器
- 工作总结:程序员该有的美好品德
- Android 中内存泄漏的原因和解决方案
- 从数据小白到大赛黑马,他们如是说 | 专访2017中国高校SAS数据分析大赛亚军团队
- 零基础如何学习java及java语言的知识要点!
- 生成PHP缩略图
- 常用linux命令大全
- ecmall导入Excel
- JavaScript slice() 方法
- 【Android测试】【第十二节】Uiautomator——API详解
- Angular自定义过滤器
- java截取2个指定字符之间的字符串
- 本地maven仓库清理(java代码)
- 给定一个5*5的矩阵(数学上,一个r×c的矩阵是一个由r行c列元素排列成的矩形阵列),将第n行和第m行交换,输出交换后的结果。