Php生成图片的大小单位是cm,php生成图片缩略图代码类
生成多种类型的缩略图
/***************************************
*作者:落梦天蝎(beluckly)
*完成时间:2006-12-18
*类名:CreatMiniature
*功能:生成多种类型的缩略图
*基本参数:$srcFile,$echoType
*方法用到的参数:
$toFile,生成的文件
$toW,生成的宽
$toH,生成的高
$bk1,背景颜色参数 以255为最高
$bk2,背景颜色参数
$bk3,背景颜色参数
*例子:
include("thumb.php");
$cm=new CreatMiniature();
$cm->SetVar("1.jpg","file");
$cm->Distortion("dis_bei.jpg",150,200);
$cm->Prorate("pro_bei.jpg",150,200);
$cm->Cut("cut_bei.jpg",150,200);
$cm->BackFill("fill_bei.jpg",150,200);
***************************************/
class CreatMiniature
{
//公共变量
var $srcFile=""; //原图
var $echoType; //输出图片类型,link--不保存为文件;file--保存为文件
var $im=""; //临时变量
var $srcW=""; //原图宽
var $srcH=""; //原图高
//设置变量及初始化
function SetVar($srcFile,$echoType)
{
$this->srcFile=$srcFile;
$this->echoType=$echoType;
$info = "";
$data = GetImageSize($this->srcFile,$info);
switch ($data[2])
{
case 1:
if(!function_exists("imagecreatefromgif")){
echo "你的GD库不能使用GIF格式的图片,请使用Jpeg或PNG格式!返回";
exit();
}
$this->im = ImageCreateFromGIF($this->srcFile);
break;
case 2:
if(!function_exists("imagecreatefromjpeg")){
echo "你的GD库不能使用jpeg格式的图片,请使用其它格式的图片!返回";
exit();
}
$this->im = ImageCreateFromJpeg($this->srcFile);
break;
case 3:
$this->im = ImageCreateFromPNG($this->srcFile);
break;
}
$this->srcW=ImageSX($this->im);
$this->srcH=ImageSY($this->im);
}
//生成扭曲型缩图
function Distortion($toFile,$toW,$toH)
{
$cImg=$this->CreatImage($this->im,$toW,$toH,0,0,0,0,$this->srcW,$this->srcH);
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}
//生成按比例缩放的缩图
function Prorate($toFile,$toW,$toH)
{
$toWH=$toW/$toH;
$srcWH=$this->srcW/$this->srcH;
if($toWH< =$srcWH)
{
$ftoW=$toW;
$ftoH=$ftoW*($this->srcH/$this->srcW);
}
else
{
$ftoH=$toH;
$ftoW=$ftoH*($this->srcW/$this->srcH);
}
if($this->srcW>$toW||$this->srcH>$toH)
{
$cImg=$this->CreatImage($this->im,$ftoW,$ftoH,0,0,0,0,$this->srcW,$this->srcH);
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}
else
{
$cImg=$this->CreatImage($this->im,$this->srcW,$this->srcH,0,0,0,0,$this->srcW,$this->srcH);
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}
}
//生成最小裁剪后的缩图
function Cut($toFile,$toW,$toH)
{
$toWH=$toW/$toH;
$srcWH=$this->srcW/$this->srcH;
if($toWH< =$srcWH)
{
$ctoH=$toH;
$ctoW=$ctoH*($this->srcW/$this->srcH);
}
else
{
$ctoW=$toW;
$ctoH=$ctoW*($this->srcH/$this->srcW);
}
$allImg=$this->CreatImage($this->im,$ctoW,$ctoH,0,0,0,0,$this->srcW,$this->srcH);
$cImg=$this->CreatImage($allImg,$toW,$toH,0,0,($ctoW-$toW)/2,($ctoH-$toH)/2,$toW,$toH);
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
ImageDestroy($allImg);
}
//生成背景填充的缩图
function BackFill($toFile,$toW,$toH,$bk1=255,$bk2=255,$bk3=255)
{
$toWH=$toW/$toH;
$srcWH=$this->srcW/$this->srcH;
if($toWH< =$srcWH)
{
$ftoW=$toW;
$ftoH=$ftoW*($this->srcH/$this->srcW);
}
else
{
$ftoH=$toH;
$ftoW=$ftoH*($this->srcW/$this->srcH);
}
if(function_exists("imagecreatetruecolor"))
{
@$cImg=ImageCreateTrueColor($toW,$toH);
if(!$cImg)
{
$cImg=ImageCreate($toW,$toH);
}
}
else
{
$cImg=ImageCreate($toW,$toH);
}
$backcolor = imagecolorallocate($cImg, $bk1, $bk2, $bk3); //填充的背景颜色
ImageFilledRectangle($cImg,0,0,$toW,$toH,$backcolor);
if($this->srcW>$toW||$this->srcH>$toH)
{
$proImg=$this->CreatImage($this->im,$ftoW,$ftoH,0,0,0,0,$this->srcW,$this->srcH);
/*
if($ftoW< $toW)
{
ImageCopyMerge($cImg,$proImg,($toW-$ftoW)/2,0,0,0,$ftoW,$ftoH,100);
}
else if($ftoH
{
ImageCopyMerge($cImg,$proImg,0,($toH-$ftoH)/2,0,0,$ftoW,$ftoH,100);
}
*/
if($ftoW
{
ImageCopy($cImg,$proImg,($toW-$ftoW)/2,0,0,0,$ftoW,$ftoH);
}
else if($ftoH
{
ImageCopy($cImg,$proImg,0,($toH-$ftoH)/2,0,0,$ftoW,$ftoH);
}
else
{
ImageCopy($cImg,$proImg,0,0,0,0,$ftoW,$ftoH);
}
}
else
{
ImageCopyMerge($cImg,$this->im,($toW-$ftoW)/2,($toH-$ftoH)/2,0,0,$ftoW,$ftoH,100);
}
return $this->EchoImage($cImg,$toFile);
ImageDestroy($cImg);
}
function CreatImage($img,$creatW,$creatH,$dstX,$dstY,$srcX,$srcY,$srcImgW,$srcImgH)
{
if(function_exists("imagecreatetruecolor"))
{
@$creatImg = ImageCreateTrueColor($creatW,$creatH);
if($creatImg)
ImageCopyResampled($creatImg,$img,$dstX,$dstY,$srcX,$srcY,$creatW,$creatH,$srcImgW,$srcImgH);
else
{
$creatImg=ImageCreate($creatW,$creatH);
ImageCopyResized($creatImg,$img,$dstX,$dstY,$srcX,$srcY,$creatW,$creatH,$srcImgW,$srcImgH);
}
}
else
{
$creatImg=ImageCreate($creatW,$creatH);
ImageCopyResized($creatImg,$img,$dstX,$dstY,$srcX,$srcY,$creatW,$creatH,$srcImgW,$srcImgH);
}
return $creatImg;
}
//输出图片,link---只输出,不保存文件。file--保存为文件
function EchoImage($img,$to_File)
{
switch($this->echoType)
{
case "link":
if(function_exists('imagejpeg')) return ImageJpeg($img);
else return ImagePNG($img);
break;
case "file":
if(function_exists('imagejpeg')) return ImageJpeg($img,$to_File);
else return ImagePNG($img,$to_File);
break;
}
}
}
?>
Php生成图片的大小单位是cm,php生成图片缩略图代码类相关推荐
- Php生成图片的大小单位是cm,图样中的尺寸大小是以厘米为单位 ()
"美玉无瑕"指的是前身为神瑛侍者的贾宝玉. 根据支付结算法律制度的规定,下列各项中,属于银行本票必须记载事项的有( ) 是第( )象限角: 是第( )象限角: 是第( )象限角: ...
- 我们知道计算机的大小单位有 B, KB, MB 等,现在请你编写一个计算器进行大小单位换算。Java洛谷传智杯
题目描述: 我们知道计算机的大小单位有 B, KB, MB 等,现在请你编写一个计算器进行大小单位换算. 输入格式:输入一个字符串,由一个 0 到 1023 之间的整数,一个单位名称(大写字母),一个 ...
- css中的单位换算_css大小单位px em rem的转换和详解
css大小单位px em rem的转换和详解 PX特点 1. IE无法调整那些使用px作为单位的字体大小: 2. 国外的大部分网站能够调整的原因在于其使用了em或rem作为字体单位: 3. Firef ...
- 内存容量大小单位转换
内存容量大小单位转换 B(Byte): 1Byte 等于 8bit KB: 1KB等于1024B MB: 1MB等于1024KB GB: 1GB等于1024MB TB: 1TB等于1024GB PB: ...
- Android大小单位转换工具类
package com.utouu.im.util; /** * Android大小单位转换工具类 * * */ public class DisplayUtil { /** * 将px值 ...
- Flutter 大小单位详解
关于Flutter 大小所使用的单位,官方文档没有给出非常明确的解释,因此一直存在模糊的说法,许多从事安卓开发者直接将之解释为安卓开发所用的单位dp,我认为这是非常不明智且不准确的说法,这个不准确不在 ...
- html vh和百分比,css中height 100vh的应用场景,动态高度百分比布局,浏览器视区大小单位...
css中height 100vh的应用场景,动态高度百分比布局,浏览器视区大小单位 height:100vh 一些只能vw, vh才能完成的应用场景: 1. 场景之:元素的尺寸限制 vw vh 主要是 ...
- php 缩略图生成类,php生成图片缩略图类
/** * @abstract 生成图片的缩略图,可以指定任意尺寸,生成的图片为png格式 * @example * $file = 'test.png'; * $th =new Thumbnail( ...
- jquery实现上传图片及图片大小验证、图片预览效果代码
jquery实现上传图片及图片大小验证.图片预览效果代码 jquery实现上传图片及图片大小验证.图片预览效果代码 上传图片验证 */ function submit_upload_picture() ...
- php生成固定大小缩略图变形,php按指定大小等比缩放生成上传图片缩略图_PHP教程...
php教程按指定大小等比缩放生成上传图片缩略图 /** * * *等比缩放 * @param unknown_type $srcImage 源图片路径 * @param unknown_type $t ...
最新文章
- 十进制转化为二进制java代码_【模板小程序】任意长度十进制数转化为二进制(java实现)...
- TEE(Trusted Execution Environment)简介
- 这个公式竟然堪称数学界的画家......
- syslog-ng按源ip保存记录
- 通过历史控制文件恢复Oracle数据库,只需这10步
- spring-boot-redis-cluster简单整合例子
- html在线布局,HTML 布局
- 电容的q值计算公式_(生活小贴士)一分钟了解“三星贴片电容的结构与材料特性”...
- Visual Assist X是个好东西呀
- LXM音频处理软件 使用说明书
- 解决网页打开慢/正在解析主机问题
- 【设计】1359- Umi3 如何实现插件化架构
- android移动日记代码,Android开源项目-小熊日记源码
- win10鼠标右键问题,导致桌面刷新重启,资源管理器explorer重启,文件夹闪退,应用管理员模式无法运行等等
- Classifier-Free Diffusion Guidance【论文精读加代码实战】
- python列表查找整数_Python:找出整数列表是否为coheren
- 2021最全 深圳互联网公司
- 不安装Office操作Excel文件(.xlsx)
- [C语言] 联想手机szb格式的制作工具,部分开源代码(仅提供程序思想);
- blender 常用修改器
热门文章
- 分销系统之项目架构(第一篇)
- 微信openid的生成规则研究
- WIN10系统不小心点击了显示语言栏怎么恢复
- [句子成分] 一、主语
- android系统内置第三方app
- 论文翻译:2021_Performance optimizations on deep noise suppression models
- Word导出PDF后,PDF没有生成Word中对应的目录
- 基于51单片机的PC机控制系统
- matplotlib之pyplot模块——绘制对数线图(loglog()、semilogx()、semilogy())
- 无线桥接dns服务器未响应,小米路由器AX3600恢复出厂设置的方法