2010-06-22 96 views
-4

我需要一些方法来动态优化使用PHP的图像。示例代码或模块将非常有用。谢谢。PHP图像优化

+0

ps:没有人知道你的意思是“动态优化图像”。优化......怎么样?对于文件大小?为了图像清晰? “动态”是什么意思? – mpen 2010-06-22 01:59:58

回答

1

你是什么意思优化?如果您希望保留尺寸但缩小尺寸,请参阅imageJpeg以获取示例,特别是第三个参数(quality)。考虑100是完美的质量,并开始减少它,以找到质量和尺寸之间的最佳平衡。

4

可以使用thimthumb.php

去你的.htaccess

不是增加

<IfModule mod_rewrite.c> 
    Options +FollowSymLinks 
    RewriteEngine On 
    RewriteRule ^(.*\.(png|jpg))$ /timthumb.php?q=100&src=$1 
</IfModule> 

“Q = 100” 是质量你可以设置它介乎0-100 比在主目录中创建一个新文件“img.php”例如:www.your-website.com/timthumb.php

http://timthumb.googlecode.com/svn/trunk/timthumb.php

比找到这个

// Get original width and height 
     $width = imagesx ($image); 
     $height = imagesy ($image); 
     $origin_x = 0; 
     $origin_y = 0; 

     // generate new w/h if not provided 
     if ($new_width && !$new_height) { 
      $new_height = floor ($height * ($new_width/$width)); 
     } else if ($new_height && !$new_width) { 
      $new_width = floor ($width * ($new_height/$height)); 
     } 

以及与此

// Get original width and height 
    $width = imagesx ($image); 
    $height = imagesy ($image); 
    $origin_x = 0; 
    $origin_y = 0; 

    // don't allow new width or height to be greater than the original  
    if($new_width > $width) {  
     $new_width = $width;   
    }  
    if($new_height > $height) {  
     $new_height = $height;  
    } 

    // generate new w/h if not provided 
    if ($new_width && !$new_height) { 
     $new_height = floor ($height * ($new_width/$width)); 
    } else if ($new_height && !$new_width) { 
     $new_width = floor ($width * ($new_height/$height)); 
    } 

替换,所以当你去www.your-website.com/images/pict.png它就像你的加载 WWW。 your-website.com/img.php?q=100 & src =/images/pict.png 希望你喜欢这个! &对不起,如果我不能很好地解释,因为我的英语不好。 :D

0

非常简单的一个也在这里: 只需将质量值(60)从1改为100就可以了。

脚本执行后,看看文件大小,这就是说,定义你的最佳质量值。

source