全球主机交流论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

CeraNetworks网络延迟测速工具IP归属甄别会员请立即修改密码
查看: 2705|回复: 6
打印 上一主题 下一主题

[疑问] 图片站站长们 你们用什么压缩图片!!

[复制链接]
跳转到指定楼层
1#
发表于 2009-9-17 10:30:40 | 只看该作者 回帖奖励 |正序浏览 |阅读模式
最近找了点高清套图!!!!!!!!!

都1-2M 分辨率超高   用百度HI 压缩不错  不过还得一张一张上传   无语了!!

织梦又没有自动压缩
7#
发表于 2009-9-17 11:08:49 | 只看该作者

回复 6# 的帖子

保存为.php文件
6#
 楼主| 发表于 2009-9-17 11:04:05 | 只看该作者
怎么使
5#
发表于 2009-9-17 11:02:32 | 只看该作者
  1. <?



  2. /* +-------------------------------------------------------------+

  3. * | Copyright (c) 2008-2009 Diqiye.Com All rights reserved.        

  4. * +-------------------------------------------------------------+

  5. * | Info : 图像处理类

  6. * +-------------------------------------------------------------+

  7. */



  8. class image {

  9.         // 当前图片

  10.         protected $img;

  11.         // 图像types 对应表

  12.         protected $types = array(

  13.                         1 => 'gif',

  14.                         2 => 'jpg',

  15.                         3 => 'png',

  16.                         6 => 'bmp'

  17.                     );

  18.         

  19.         // image

  20.         public function __construct($img=''){

  21.                 !$img && $this->param($img);

  22.         }

  23.         

  24.         // Info

  25.         public function param($img){

  26.                 $this->img = $img;

  27.                 return $this;

  28.         }

  29.         

  30.         // imageInfo

  31.         public function getImageInfo($img){

  32.                 $info = @getimagesize($img);

  33.                 if(isset($this->types[$info[2]])){

  34.                         $info['ext'] = $info['type'] = $this->types[$info[2]];

  35.                 } else{

  36.                         $info['ext'] = $info['type'] = 'jpg';

  37.                 }

  38.                 $info['type'] == 'jpg' && $info['type'] = 'jpeg';

  39.                 $info['size'] = @filesize($img);

  40.                 return $info;

  41.         }

  42.         

  43.         // thumb(新图地址, 宽, 高, 裁剪, 允许放大)

  44.         public function thumb($filename,$new_w=160,$new_h=120,$cut=0,$big=0){

  45.         // 获取原图信息   

  46.         $info  = $this->getImageInfo($this->img);

  47.         if(!empty($info[0])) {

  48.             $old_w  = $info[0];

  49.             $old_h  = $info[1];

  50.             $type   = $info['type'];

  51.             $ext    = $info['ext'];

  52.             unset($info);



  53.                         if(!in_array($type, array('jpeg', 'gif', 'png'))){

  54.                                 return false;

  55.                         }



  56.             // 如果原图比缩略图小 并且不允许放大

  57.             if($old_w < $new_h && $old_h < $new_w && !$big){

  58.                     return false;

  59.             }

  60.             // 裁剪图片

  61.             if($cut == 0){ // 等比列

  62.                     $scale = min($new_w/$old_w, $new_h/$old_h); // 计算缩放比例

  63.                     $width  = (int)($old_w*$scale); // 缩略图尺寸

  64.                     $height = (int)($old_h*$scale);

  65.                     $start_w = $start_h = 0;

  66.                     $end_w = $old_w;

  67.                     $end_h = $old_h;

  68.             } elseif($cut == 1){ // center center 裁剪

  69.                         $scale1 = round($new_w/$new_h,2);

  70.                         $scale2 = round($old_w/$old_h,2);

  71.                         if($scale1 > $scale2){

  72.                                 $end_h = round($old_w/$scale1,2);

  73.                                 $start_h = ($old_h-$end_h)/2;

  74.                                 $start_w  = 0;

  75.                                 $end_w    = $old_w;

  76.                         } else{

  77.                                 $end_w  = round($old_h*$scale1,2);

  78.                                 $start_w  = ($old_w-$end_w)/2;

  79.                                 $start_h = 0;

  80.                                 $end_h   = $old_h;

  81.                         }

  82.                         $width = $new_w;

  83.                     $height= $new_h;

  84.                 } elseif($cut == 2){ // left top 裁剪           

  85.                         $scale1 = round($new_w/$new_h,2);

  86.                     $scale2 = round($old_w/$old_h,2);

  87.                     if($scale1 > $scale2){

  88.                             $end_h = round($old_w/$scale1,2);

  89.                             $end_w = $old_w;

  90.                     } else{

  91.                             $end_w = round($old_h*$scale1,2);

  92.                             $end_h = $old_h;

  93.                     }

  94.                     $start_w = 0;

  95.                     $start_h = 0;

  96.                     $width = $new_w;

  97.                     $height= $new_h;

  98.                 }

  99.             // 载入原图

  100.             $createFun  = 'ImageCreateFrom'.$type;

  101.             $oldimg     = $createFun($this->img);

  102.             // 创建缩略图

  103.             if($type!='gif' && function_exists('imagecreatetruecolor')){

  104.                 $newimg = imagecreatetruecolor($width, $height);

  105.             } else{

  106.                 $newimg = imagecreate($width, $height);

  107.             }

  108.             // 复制图片

  109.             if(function_exists("ImageCopyResampled")){

  110.                     ImageCopyResampled($newimg, $oldimg, 0, 0, $start_w, $start_h, $width, $height, $end_w,$end_h);

  111.             } else{

  112.                 ImageCopyResized($newimg, $oldimg, 0, 0, $start_w, $start_h, $width, $height, $end_w,$end_h);

  113.             }



  114.             // 对jpeg图形设置隔行扫描

  115.             $type == 'jpeg' && imageinterlace($newimg,1);

  116.             // 生成图片

  117.             $imageFun = 'image'.$type;

  118.             !@$imageFun($newimg, $filename, 100) && die('保存失败!检查目录是否存在并且可写?');

  119.             ImageDestroy($newimg);

  120.             ImageDestroy($oldimg);

  121.             return $filename;

  122.         }

  123.         return false;

  124.     }

  125.    

  126. }

  127. ?>
复制代码
4#
发表于 2009-9-17 10:35:19 | 只看该作者

回复 3# 的帖子

向百度讨要技术
3#
 楼主| 发表于 2009-9-17 10:34:32 | 只看该作者
百度HI 空间  自动压缩真不错!!! 而且不失真
2#
发表于 2009-9-17 10:33:47 | 只看该作者

回复 1# 的帖子

我不是图片站站长。

你可以看看什么软件可以帮上你的忙。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|全球主机交流论坛

GMT+8, 2025-12-26 05:27 , Processed in 0.133460 second(s), 11 queries , Gzip On, MemCache On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表