<?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. hdu_5876_Sparse Graph(补图BFS)

    题目链接:hdu_5876_Sparse Graph 附上叉姐的题解: 1009 Sparse Graph [by ftiasch] 题意:n 个点的无向完全图中删除 m 条边,问点 s 到其他点的最 ...

  2. 更好列表页中一个航班.先unset删除数组中一个键值对,再追加,最后按键排序

    <?php $arr = array( '0' => array('item' => array( 'aa' => 'aaa', 'bb' => 'bbb' )), '1 ...

  3. flex安装debug

    1.解决 不是最新版本的问题: cmd-->regedit-->HKEY_LOCAL_MATCHING-->SOFTWARE-->MACROMEDIA -->FLASHP ...

  4. HDU 3835 R(N)(枚举)

    题目链接 Problem Description We know that some positive integer x can be expressed as x=A^2+B^2(A,B are ...

  5. MVC3+EF4.1学习系列(十)----MVC+EF处理树形结构

    通过前几篇文章 我们处理了 一对一, 一对多,多对多关系 很好的发挥了ORM框架的做用 但是 少说了一种 树形结构的处理, 而这种树形关系 我们也经常遇到,常见的N级类别的处理, 以及经常有数据与类别 ...

  6. [ An Ac a Day ^_^ ] FZU 2030 括号问题 搜索

    FZU一直交不上去 先写在这吧 #include<stdio.h> #include<iostream> #include<algorithm> #include& ...

  7. ios中获取当前屏幕尺寸的方法

    //获取当前屏幕尺寸 CGRect screenFrame = [UIScreen mainScreen].bounds; int screenWidth = screenFrame.size.wid ...

  8. redis的常用命令

    键值得相关命令: keys * 返回满足给定patternd的所有key exists 确认一个key是否存在 del 删除一个key expire 设置一个key的过期时间 ttl 查看过期时间还有 ...

  9. 带宽 VS CDN (转载)

    并发的影响因素:带宽.web server(含php).static server.数据库 带宽价格: 静态IP企业宽带 5M 10M 50M 100M 200M 盛大云 华东双线 216/月 396 ...

  10. hashMap、hashTable、treeMap的区别

    1.hashTable是线程安全的.hashMap不是线程安全的 hashmap 线程不安全 允许有null的键和值 效率高一点. 方法不是Synchronize的要提供外同步 有containsva ...