zoukankan      html  css  js  c++  java
  • PHP 压缩图片质量

    $imageFileName = './test2.jpg';
    $uploadfile_resize = $imageFileName;
    $pic_width_max = 1000;
    $pic_height_max = 1000;
    $file_type = getimagesize($imageFileName)['mime'];

    if($file_type == "image/pjpeg"||$file_type == "image/jpg"|$file_type == "image/jpeg"){
    $im = imagecreatefromjpeg($imageFileName);
    }else if($file_type == "image/x-png"){
    $im = imagecreatefromjpeg($imageFileName);
    }else if($file_type == "image/gif"){
    $im = imagecreatefromjpeg($imageFileName);
    }else {//默认jpg
    $im = imagecreatefromjpeg($imageFileName);
    }
    if($im) {
    ResizeImage($im, $pic_width_max, $pic_height_max, $uploadfile_resize);
    ImageDestroy($im);
    }



    function resizeImage($uploadfile,$maxwidth,$maxheight,$filename){
    //取得当前图片大小
    $width = imagesx($uploadfile);
    $height = imagesy($uploadfile);

    //压缩比值
    $i=0.5;
    //生成缩略图的大小
    if(($width > $maxwidth) || ($height > $maxheight)){
    $newwidth = $width * $i;
    $newheight = $height * $i;
    if(function_exists("imagecopyresampled")){
    $uploaddir_resize = imagecreatetruecolor($newwidth, $newheight);
    //echo $uploaddir_resize;
    imagecopyresampled($uploaddir_resize, $uploadfile, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    }else{
    $uploaddir_resize = imagecreate($newwidth, $newheight);
    imagecopyresized($uploaddir_resize, $uploadfile, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
    }

    ImageJpeg ($uploaddir_resize,$filename);
    ImageDestroy ($uploaddir_resize);
    }else{
    ImageJpeg ($uploadfile,$filename);
    }
    }
  • 相关阅读:
    Storm:分布式流式计算框架
    GreenPlum:基于PostgreSQL的分布式关系型数据库
    Hive和SparkSQL: 基于 Hadoop 的数据仓库工具
    Linux网络子系统
    Python标准模块--multiprocessing
    Python标准模块--built-ins函数
    Python标准模块--threading
    Python标准模块--import
    Python标准模块--os
    Python标准模块--argparse
  • 原文地址:https://www.cnblogs.com/wenxinphp/p/10083348.html
Copyright © 2011-2022 走看看