2013-02-10 3 views
0

업로드 된 이미지를 원래 형식 (jpg, jpeg rpng 등)으로 변환하고 싶지만이 이미지의 크기를 150px 너비와 210px 높이로 다시 조정해야합니다. 복사하는 동안 크기를 변경할 수 있습니까, 아니면 변환해야합니까? 업로드 된 이미지 : 변환 형식

은 unsucessful했다 : 당신은 GD 대신 는 FFmpeg로 사용할 수 있습니다

$uploaddir1 = "/home/myweb/public_html/temp/sfds454.png"; 
    $uploaddir2 = "/home/myweb/public_html/images/sfds454.png"; 

    $cmd = "/usr/bin/ffmpeg -i $uploaddir1 -vframes 1 -s 150x210 -r 1 -f mjpeg $uploaddir2"; 
    @exec($cmd); 

답변

1

최근 다만이 문제를 해결했고,이 간단한 캐싱 솔루션 구현 : 나는하지 않았다하더라도,

  1. Graphicsmagick가 ImageMagick를보다 빠르게 변환 : 내가 발견

    <?php 
    function send($name, $ext) { 
        $fp = fopen($name, 'rb'); 
        // send the right headers 
        header("Content-Type: image/$ext"); 
        header("Content-Length: " . filesize($name)); 
    
        // dump the picture and stop the script 
        fpassthru($fp); 
        exit; 
    } 
    
    error_reporting(E_ALL); 
    ini_set('display_errors', 'On'); 
    
    if (isset($_REQUEST['fp'])) { 
        $ext = pathinfo($_REQUEST['fp'], PATHINFO_EXTENSION); 
    
        $allowedExt = array('png', 'jpg', 'jpeg'); 
        if (!in_array($ext, $allowedExt)) { 
         echo 'fail'; 
        } 
    
        if (!isset($_REQUEST['w']) && !isset($_REQUEST['h'])) { 
         send($_REQUEST['fp']); 
        } 
        else { 
         $w = $_REQUEST['w']; 
         $h = $_REQUEST['h']; 
    
         //use height, width, modification time and path to generate a hash 
         //that will become the file name 
         $filePath = realpath($_REQUEST['fp']); 
         $cachePath = md5($filePath.filemtime($filePath).$h.$w); 
         if (!file_exists("tmp/$cachePath")) { 
          exec("gm convert -quality 80% -colorspace RGB -resize " .$w .'x' . $h . " $filePath tmp/$cachePath"); 
         } 
         send("tmp/$cachePath", $ext); 
    
        } 
    } 
    ?> 
    

    몇 가지 cuda 처리로 테스트 변환.

  2. 최종 제품의 경우 언어의 기본 그래픽 라이브러리를 사용하여 ASP에서이 코드를 다시 구현했습니다. 이것은 다시 빠르지 만 메모리 부족 오류가 발생하면 중단됩니다 (워크 스테이션에서는 정상적으로 작동하지만 4GB RAM 서버에서는 작동하지 않음).
관련 문제