2010-06-22 8 views
-4

PHP를 사용하여 이미지를 동적으로 최적화하는 방법이 필요합니다. 샘플 코드 또는 모듈은 매우 유용합니다. 감사.PHP 이미지 최적화

+0

ps : 아무도 이미지를 동적으로 최적화하지 않습니다. 최적화 ... 어떻게? 파일 크기는? 이미지 선명도? "동적"이란 무엇을 의미합니까? – mpen

답변

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

// 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)); 
     } 

을 찾아 당신이 당신의로드 WWW처럼 www.your-website.com/images/pict.png로 이동하므로 때이

// 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)); 
    } 

로 교체보다

. your-website.com/img.php?q=100 & src =/images/pict.png 당신이 이것을 좋아하길 바랍니다! & 미안하지만 내 영어가 좋지 않아서 내가 잘 explaing 수 없습니다. : D

0

매우 간단한 것도 여기에 있습니다. 원하는대로 품질 값 (60)을 1에서 100으로 변경하십시오.

스크립트를 실행 한 후 파일 크기를 살펴보고 그 최적의 품질 값을 정의하십시오.

source