Home > php教程 > PHP源码 > 改写jcrop插件+php的图片上传实现与裁剪一体化

改写jcrop插件+php的图片上传实现与裁剪一体化

PHP中文网
Release: 2016-05-25 17:06:33
Original
1135 people have browsed it

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

1. [文件]     mytest.zip 

 改写jcrop插件+php的图片上传实现与裁剪一体化mytest.zip

2. [图片] QQ截图20130416094207.jpg    

 改写jcrop插件+php的图片上传实现与裁剪一体化


3. [代码][PHP]代码  

<?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[&#39;act&#39;]) && $_GET[&#39;act&#39;] == "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 &#39;<img src="&#39;.$res[&#39;big&#39;].&#39;" style="margin:10px;">&#39;; 
echo &#39;<img src="&#39;.$res[&#39;small&#39;].&#39;" style="margin:10px;">&#39;; 
}elseif(is_string($res)){ 
echo &#39;<img src="&#39;.$res.&#39;">&#39;; 
} 
} 
} 
if ($_GET[&#39;act&#39;] == &#39;cut&#39;){ 
$image = $_POST["imgsrc"]; 

$res = $images->thumb($image,false,1); 
if($res == false){ 
echo "裁剪失败"; 
}elseif(is_array($res)){ 
echo &#39;<img src="&#39;.$res[&#39;big&#39;].&#39;" style="margin:10px;">&#39;; 
echo &#39;<img src="&#39;.$res[&#39;small&#39;].&#39;" style="margin:10px;">&#39;; 
}elseif(is_string($res)){ 
echo &#39;<img src="&#39;.$res.&#39;">&#39;; 
} 
} 
?>
Copy after login



Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template