//参数1 文件名 参数2 缩放比例
function _thumb($_filename,$_percent){
ob_clean();
//生成png标头文件
header('Content-type:image/png');
$_n=explode('.', $_filename);
//获取文件的信息,宽和高
list($_width,$_height)=getimagesize($_filename);
//生成缩略后的大小
$_new_width=$_width*$_percent;
$_new_height=$_height*$_percent;
//按照新的大小创建微缩画布
$_new_image=imagecreatetruecolor($_new_width, $_new_height);
//按照已经有的图片创建一个画布[按照图片类型]
switch($_n[1]){
case 'jpg':$_image=imagecreatefromjpeg($_filename);
break;
case 'png':$_image=imagecreatefrompng($_filename);
break;
case 'gif':$_image=imagecreatefromgif($_filename);
break;
}
//将原来的图复制到新的图片上
imagecopyresampled($_new_image, $_image, 0, 0, 0, 0, $_new_width, $_new_height, $_width, $_height);
//输出图片
imagepng($_new_image);
//销毁新资源句柄
imagedestroy($_new_image);
//销毁原资源句柄
imagedestroy($_image);
} 理解抽象类最快的方法就是使用场景,最近在看布尔PHP视频中看到这样的讲解非常容易懂,分享出来。 假设如下场景: 团队准备开发某网站,表建好了,页面设计好了. ...
md5/sha1+salt方式是目前各大cms常用的加密方式,虽然salt安全,但是各大md5网站也在研究这个方向,那么我们应该选择password_hash动态hash来助力,一种密码有多种hash结果.看代码模拟登陆.<?php //01.注册 $user ='zhang...
php官方已经提供了Iterator(迭代器)接口,通过网上资料的学习,目前看适合超大集合或者数组提取使用。学习一个函数的实现对比内存占用差距.使用迭代器和普通循环实现range()函数。(1).普通循环实现range()函数。function newrange($low, $h...
项目中使用服务来执行webservice,由于对方系统api不稳定,经常导致服务崩溃,只能重启,一个月差不多要重启一次。初期的解决办法是捕获异常,然后continue掉。<?php try { $url = 'http...
逛公众号文章看到文章"php实现事件监听与触发的方法,你用过吗?",我就好奇了,php又不是asp.net的webform,哪里来的服务端事件监听。于是学习了一波。先看下监听类:class Event { /** &nbs...
参数中包含gb2312的字符串,返回结果是false或者null(不同PHP版本具有差异性)代码:<?php $dbms = 'mysql'; $host = '192.168.8.8'; $dbName =&n...