<?php

require dirname(__FILE__).'/../includes/common.inc.php';
$_clean = array();
$_info = array();
$_data = array();
$_clean['shopId'] =_check($_POST['shopId']);
$_clean['userId'] =_check($_POST['userId']);
$oldpic = $_FILES['picFile']['tmp_name'];
if ( $_clean['shopId']!='' && $_clean['userId']!='' ) {
$_info['state'] = ;
$_info['info'] = '';
$max_file_size=; //大小500kb
if($max_file_size <$oldpic["size"]){
$_info['state'] = ;
$_info['info'] = '文件太大';
echo _json($_info);
die;
}else{
$_sql1 = "SELECT * FROM tb_easy_Comments WHERE user = '{$_clean['userId']}' and contentId = '{$_clean['contentId']}'";
$_result1 = _query($_sql1);
$_row1 = _num_rows($_result1);
if ( $_row1 > ) {
$_info['state'] = ;
$_info['info'] = '您已经评论过';
echo _json($_info);
die;
}else{
$width = ;
$height = ;
header('Content-Type: image/jpeg,image/png,image/gif');
//获取到图片的宽和高
list($width_orig, $height_orig) = getimagesize($oldpic);
$ratio_orig = $width_orig/$height_orig;
//算比例
if ($width/$height > $ratio_orig) {
$width = $height*$ratio_orig;
} else {
$height = $width/$ratio_orig;
}
//创建
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefrompng($oldpic);
imagecopyresampled($image_p, $image, , , , , $width, $height, $width_orig, $height_orig);
$pic = date('YmdHis').rand(,).'.'.jpg;
imagejpeg($image_p,"D:/www/web/php_easyhunt/images/easyCommentsPic/".$pic , );
$_data['info'] ="http://". $_SERVER['SERVER_NAME'].'/images/easyCommentsPic/'.$pic;
$_info['data'] = $_data;
echo _json($_info);
}
}
}else{
$_data['state'] = ;
$_data['info'] = '参数有误!';
} $_info['data'] = $_data; echo _json($_info); //请勿删除以下内容 以后备用
// require dirname(__FILE__).'/../includes/common.inc.php';
// $_clean = array();
// $_info = array();
// $_data = array();
// $_clean['shopId'] =_check($_POST['shopId']);
// $_clean['userId'] =_check($_POST['userId']);
//
// $oldpic = $_FILES['picFile']['name'];
// //上传后的名称
// $newpic = date('YmdHis').rand(1000,9999).$oldpic;
//
// if ( $_clean['shopId']!='' && $_clean['userId']!='' ) {
//
// $_info['state'] = 0;
// $_info['info'] = '';
// $max_file_size=500000; //大小500kb
// if($max_file_size <$oldpic["size"]){
// $_info['state'] = 2;
// $_info['info'] = '文件太大';
// echo _json($_info);
// die;
// }
// //接收文件目录
// $target_path = "D:/www/web/php_easyhunt/images/companyImages/";
// if(move_uploaded_file($_FILES['picFile']['tmp_name'], $target_path. $newpic)) {
// }
// $_data['info'] ="http://". $_SERVER['SERVER_NAME'].'/images/companyImages/'.$newpic;
// }else{
// $_data['state'] = 5;
// $_data['info'] = '参数有误!';
//// }
//
// $_info['data'] = $_data;
//
// echo _json($_info); //
// $image_p = imagecreatetruecolor($width, $height);
// $type = substr($_absolutePath,strrpos($_absolutePath, '.')+1);
// if($type == "jpg" || $type == "JPEG"||$type == "jpeg") {
// $image = imagecreatefromjpeg($_absolutePath);
// } else if ($type == "png") {
// $image = imagecreatefrompng($_absolutePath);
// } else if ($type == "gif") {
// $image = imagecreatefromgif($_absolutePath);
// }
//
//
// function scaleImage(){
// /*$_absolutePath="http://115.28.233.45/mobile_client".$_path;*/
// $_absolutePath="http://115.28.233.45/mobile_client/imgs/comments/4_220/201412270932136d2fcd32-7764-4081-9ae5-6f85bbfadf71.JPEG";
// $width = 200;
// $height = 200;
// header('Content-Type: image/jpeg,image/png,image/gif');
// //获取到图片的宽和高
// list($width_orig, $height_orig) = getimagesize($_absolutePath);
// $ratio_orig = $width_orig/$height_orig;
// //算比例
// if ($width/$height > $ratio_orig) {
// $width = $height*$ratio_orig;
// } else {
// $height = $width/$ratio_orig;
// }
// //创建
// $image_p = imagecreatetruecolor($width, $height);
// $type = substr($_absolutePath,strrpos($_absolutePath, '.')+1);
// if($type == "jpg" || $type == "JPEG"||$type == "jpeg") {
// $image = imagecreatefromjpeg($_absolutePath);
// } else if ($type == "png") {
// $image = imagecreatefrompng($_absolutePath);
// } else if ($type == "gif") {
// $image = imagecreatefromgif($_absolutePath);
// }
// imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
// $pic ="smalll_".substr($_absolutePath,strrpos($_absolutePath, '/')+1);
// imagejpeg($image_p,"imgs/comments/".$pic , 100);
// } ?>

php 图片压缩处理的更多相关文章

  1. Golang 编写的图片压缩程序,质量、尺寸压缩,批量、单张压缩

    目录: 前序 效果图 简介 全部代码 前序: 接触 golang 不久,一直是边学边做,边总结,深深感到这门语言的魅力,等下要跟大家分享是最近项目 服务端 用到的图片压缩程序,我单独分离了出来,做成了 ...

  2. 三款不错的图片压缩上传插件(webuploader+localResizeIMG4+LUploader)

    涉及到网页图片的交互,少不了图片的压缩上传,相关的插件有很多,相信大家都有用过,这里我就推荐三款,至于好处就仁者见仁喽: 1.名气最高的WebUploader,由Baidu FEX 团队开发,以H5为 ...

  3. 前端构建工具之gulp(一)「图片压缩」

    前端构建工具之gulp(一)「图片压缩」 已经很久没有写过博客了,现下终于事情少了,开始写博吧 今天网站要做一些优化:图片压缩,资源合并等 以前一直使用百度的FIS工具,但是FIS还没有提供图片压缩的 ...

  4. gulp图片压缩

    gulp图片压缩 网页性能优化,通常要处理图片,尤其图片量大的时候,更需要工具来批量处理,这里使用gulp,做个简单总结 image-resize压缩尺寸 var gulp = require('gu ...

  5. Android 图片压缩、照片选择、裁剪,上传、一整套图片解决方案

    1.Android一整套图片解决方案 http://mp.weixin.qq.com/s?__biz=MzAxMTI4MTkwNQ==&mid=2650820998&idx=1& ...

  6. Java中图片压缩处理

    原文http://cuisuqiang.iteye.com/blog/2045855 整理文档,搜刮出一个Java做图片压缩的代码,稍微整理精简一下做下分享. 首先,要压缩的图片格式不能说动态图片,你 ...

  7. android 图片压缩

    引用:http://104zz.iteye.com/blog/1694762 第一:我们先看下质量压缩方法: private Bitmap compressImage(Bitmap image) { ...

  8. HTML5 CANVAS 实现图片压缩和裁切

    原文地址:http://leonshi.com/2015/10/31/html5-canvas-image-compress-crop/?utm_source=tuicool&utm_medi ...

  9. C# 图片压缩

    /// <summary>        /// 图片压缩方法        /// </summary>        /// <param name="sF ...

  10. Html5+asp.net mvc 图片压缩上传

    在做图片上传时,大图片如果没有压缩直接上传时间会非常长,因为有的图片太大,传到服务器上再压缩太慢了,而且损耗流量. 思路是将图片抽样显示在canvas上,然后用通过canvas.toDataURL方法 ...

随机推荐

  1. javascript基础(二)类型转换

    原文http://pij.robinqu.me/ 类型转换 当期望使用一个布尔值的时候,可以提供任意类型值,JavaScript将根据需要自行转换类型.类型转换可以分为隐式转换和显式转换. 显式转换 ...

  2. @Transactional注解详解

    默认遇到throw new RuntimeException("...");会回滚   需要捕获的throw new Exception("...");不会回滚 ...

  3. IOS真机Profile时调用树中的对象只是显示地址,没有显示symbol name

    解决问题的办法: 1.确认工程设置中的Scheme,profile选项对应的是debug版本还是release版本 2.确认工程设置中debug版本或者release版本是否生成了符号表 " ...

  4. jQuery实例2

    下拉框实例: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...

  5. css3的特效拓展...

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  6. ThinkPHP模板

    [MVC模式] M:Model 数据模型层,负责数据操作 V:View 视图层,负责显示视图 C:Controller 控制器,实现业务逻辑 tp框架url地址可以由以下四种 http://网址/in ...

  7. dd if=/dev/zero of=的含义是什么?Linux 下的dd命令使用详解

    http://blog.sina.com.cn/s/blog_8b5bb24f01016y3o.html 一.dd命令的解释 dd:用指定大小的块拷贝一个文件,并在拷贝的同时进行指定的转换. 注意:指 ...

  8. Hibernate框架--配置,映射,主键

    SSH框架: Struts框架, 基于mvc模式的应用层框架技术! Hibernate,    基于持久层的框架(数据访问层使用)! Spring,   创建对象处理对象的依赖关系以及框架整合! Da ...

  9. iOS中控制器的释放问题

    iOS中控制器的释放问题 ARC工程是可以重写dealloc方法并被系统调用的,但不需要手动调用父类的dealloc,手写[super dealloc]方法会报错,事实上系统会自动帮你调用父类的dea ...

  10. Screen tearing

    Umm, screen tearing happens when the frame rate and the monitor refresh rate don't match.  When that ...