<?php
/**
* 生成缩略图函数(支持图片格式:gif、jpeg、png和bmp)
* @author ruxing.li
* @param string $src 源图片路径
* @param int $width 缩略图宽度(只指定高度时进行等比缩放)
* @param int $width 缩略图高度(只指定宽度时进行等比缩放)
* @param string $filename 保存路径(不指定时直接输出到浏览器)
* @return bool
*/
function mkThumbnail($src, $width = null, $height = null, $filename = null) {
if (!isset($width) && !isset($height))
return false;
if (isset($width) && $width <= )
return false;
if (isset($height) && $height <= )
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 :
$img_type = 'gif';
break;
case :
$img_type = 'jpeg';
break;
case :
$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, , , , , $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('1.jpg', ,);

PHP 生成图片缩略图函数的更多相关文章

  1. JAVA生成图片缩略图、JAVA截取图片局部内容

    package com.ares.image.test; import java.awt.Color; import java.awt.Graphics; import java.awt.Image; ...

  2. PHP原生写的生成图片缩略图类

    PHP原生写的生成图片缩略图类,本文以京东商品图片为例,分别生成三种不同尺寸的图片.调用方法很简单只要传参数高度和宽度,及新图片的名称. 引入缩略图类 include_once 'ImageResiz ...

  3. php生成图片缩略图的类方法

    //php生成缩略图片的类 class ResizeImage{ public $type;//图片类型 public $width;//实际宽度 public $height;//实际高度 publ ...

  4. C# 生成图片缩略图

    最近项目有部分需求,是关于图片操作部分的, 大致的功能就是图片的保存和展示.但是直接操作原图,程序运行效率太慢.而且如果传输数据量过大的话,可能直接导致调用WCF服务失败的问题. 为了解决这个问题,决 ...

  5. php使用GD库实现图片水印和缩略图——生成图片缩略图

    今天呢,就来学习一下在php中使用PD库来实现对图片水印的文字水印方法,不需要PS哦! 首先,准备素材 (1)准备一张图片 (2)准备一张水印(最好是透明的,即背景是白色底) (3)准备一中字体(在电 ...

  6. php生成图片缩略图,支持png透明

    注:此功能依赖GD2图形库 PHP生成缩略图类   <?php /* * desc: Resize Image(png, jpg, gif) * author: 十年后的卢哥哥(http://w ...

  7. C#生成图片缩略图(2种思路)

    前言:在日常图片浏览中,如果图片过多,只有一张张的打开图片才能知道图片的内容,显然这样浏览起来非常不便.Windows系统在浏览图片时提供了缩略图的功能,这样大大的方便了浏览者了解每张图片的内容,本实 ...

  8. java生成生成图片缩略图

    /** * */ package com.fkhwl.fkhserver.core.utils; import java.awt.Image; import java.awt.image.Buffer ...

  9. Python——使用第三方库Pillow生成图片缩略图

    流程如下: 1.首先确认是否安装了pip 在命令提示符窗口下输入pip,如果Windows提示未找到命令,可以重新运行安装程序添加pip. 2.在命令提示符窗口下输入pip install Pillo ...

随机推荐

  1. 第一天的作业,登录接口脚本 login.py

    user_list = [] count = 0 user = "liruixin" password = " raw_user = raw_input("us ...

  2. JS跳出框架返回上一页

    链接部分 <a class="link" href="javascript:;" target="_top" onclick=&quo ...

  3. 浅谈我对JCS 的理解

    JCS 是Java 中缓存的一种实现,支持将数据缓存到内存和硬盘中,支持设置缓存对象的有效时长. 我认为可以这么理解JCS:客户端向服务器发出请求,服务器就先去缓存中查一下有没有客户端请求的数据,有则 ...

  4. 做WEB开发的时候,前端与后端我们应该要注意哪些细节,哪些容易出现的漏洞?

    写这篇文章的时候,我和团队正在处理项目漏洞问题,发现这些都是细节但又容易在项目实现的过程中忽视的部分,鉴于此,我想总结下来,方便以后出现类似问题能及时得到解决. 1.任意文件上传漏洞.   描述:允许 ...

  5. 【HDU 4305】Lightning(生成树计数)

    Problem Description There are N robots standing on the ground (Don't know why. Don't know how). Sudd ...

  6. 【POJ 1269】判断两直线相交

    题 利用叉积解方程 #include <cstdio> #define MAX 1<<31 #define dd double int xmult(dd x1,dd y1,dd ...

  7. python模块介绍二。

    全局变量 全局变量 python在一个.py文件内部自动添加了一些全局变量 print(vars()) #查看当前的全局变量 执行结果: {'__package__': None, '__loader ...

  8. git 笔记1

    代码 kamil@ubuntu:~/github/xzdz$ git init Initialized empty Git repository in /home/kamil/github/xzdz/ ...

  9. bzoj 1257

    商最多有sqrt(n)个. #include<iostream> #include<cstdio> #include<cstring> #include<al ...

  10. Unable to load native-hadoop library for your platform... using builtin-Java classes where applicable

    以前hadoop也有这个问题,没注意,用spark也提示,解决一下. 首先找到对应自己hadoop版本的的lib包,编译好后,名字类似hadoop-native-64-2.4.1.tar ,放到lib ...