这篇文章主要介绍了php实现从上传文件创建缩略图的方法,涉及php操作上传文件及图片操作的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
本文实例讲述了php实现从上传文件创建缩略图的方法。具体实现方法如下:
102400){
$error=1;
$msg = "The photo is over 100kb. Please try again.";
}
////////////////////////////////
// CHECK TYPE (IE AND OTHERS) //
if ($userfile_type="image/pjpeg"){
if ($userfile_type!="image/jpeg"){
$error=1;
$msg = "The photo must be JPG";
}
}
//////////////////////////////
//CHECK WIDTH/HEIGHT //
if ($large_width!=600 or$large_height!=400){
$error=1;
$msg = "The photo must be 600x400 pixels";
}
///////////////////////////////////////////
//CREATE THUMB / UPLOAD THUMB AND PHOTO ///
if ($error<>1){
$image = $userfile_name; //if you want to insert it to the database
$pic = imagecreatefromjpeg($userfile);
$small = imagecreatetruecolor($small_width,$small_height);
imagecopyresampled($small,$pic,0,0,0,0, $small_width, $small_height, $large_width, $large_height);
if (imagejpeg($small,"path/to/folder/to/upload/thumb".$userfile_name, 100)){
$large = imagecreatetruecolor($large_width,$large_height);
imagecopyresampled($large,$pic,0,0,0,0, $large_width, $large_height, $large_width, $large_height);
if (imagejpeg($large,"path/to/folder/to/upload/photo".$userfile_name, 100))
{}
else {$msg="A problem has occured. Please try again."; $error=1;}
}
else {
$msg="A problem has occured. Please try again."; $error=1;
}
}
//////////////////////////////////////////////
/// If everything went right a photo (600x400) and
/// a thumb(120x90) were uploaded to the given folders
}
?>
create thumb
总结:以上就是本篇文的全部内容,希望能对大家的学习有所帮助。
相关推荐:
将产品展示、购物管理、资金管理等功能相结合,并提供了简易的操作、丰富的功能和完善的权限管理,为用户提供了一个低成本、高效率的网上商城建设方案包含PowerEasy CMS普及版,主要功能模块:文章频道、下载频道、图片频道、留言频道、采集管理、商城模块、商城日常操作模块500个订单限制(超出限制后只能查看和删除,不能进行其他处理) 无订单处理权限分配功能(只有超级管理员才能处理订单)
立即学习“PHP免费学习笔记(深入)”;










