1.图片上传后立刻判断图片的宽和高是否超过预设的最大高度与宽度,超过了则生成缩略图,
2.图片裁剪使用的是jquery的裁剪插件Jcrop,可以实现裁剪的即时预览,
代码没有优化,会生成很多垃圾图片,欢迎大家一起改进,完善好的请分享!

<?php
error_reporting(7);
date_default_timezone_set("Asia/Shanghai");
header("Content-type:text/html; Charset=utf-8");
require_once("./image.class.php");
$images = new Images("file");
if(isset($_GET['act']) && $_GET['act'] == "upload" ){
$path = $images->move_uploaded();
$images->thumb($path,false,0); //文件比规定的尺寸大则生成缩略图,小则保持原样
if($path == false){
$images->get_errMsg();
}else{
$image = $path;
//$res = $images->thumb($image,false,1);
if($res == false){
}elseif(is_array($res)){
echo '<img src="'.$res['big'].'" style="margin:10px;">';
echo '<img src="'.$res['small'].'" style="margin:10px;">';
}elseif(is_string($res)){
echo '<img src="'.$res.'">';
}
}
}
if ($_GET['act'] == 'cut'){
$image = $_POST["imgsrc"];
$res = $images->thumb($image,false,1);
if($res == false){
echo "裁剪失败";
}elseif(is_array($res)){
echo '<img src="'.$res['big'].'" style="margin:10px;">';
echo '<img src="'.$res['small'].'" style="margin:10px;">';
}elseif(is_string($res)){
echo '<img src="'.$res.'">';
}
}
?>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号