2017-08-03 93 views
0

有base64格式的圖像($theme_image_enc$theme_image_enc_little)。現在我想讓第二張圖像($theme_image_enc_little)的大小變得像15kb一樣小。怎麼可以做到這一點?圖像文件大小較小的形式base64編碼

$image    = ($_FILES["my_image"]["name"]); 
    $theme_image  = ($_FILES["my_image"]["tmp_name"]); 
    $bin_string   = file_get_contents("$theme_image"); 
    $theme_image_enc = base64_encode($bin_string); 

    $WIDTH  = 400; // The size of your new image 
    $HEIGHT  = 300; // The size of your new image 
    $QUALITY = 100; //The quality of your new image 
    $org_w  = 850; 
    $org_h  = 660; 

    $theme_image_little  = imagecreatefromstring(base64_decode($theme_image_enc)); 
    $image_little   = imagecreatetruecolor($WIDTH, $HEIGHT); 
    imagecopyresampled($image_little, $theme_image_little, 0, 0, 0, 0, $WIDTH, $HEIGHT, $org_w, $org_h); 
    ob_start(); 
    imagepng($image_little); 
    $contents = ob_get_contents(); 
    ob_end_clean(); 

    echo $theme_image_enc_little = base64_encode($contents); 

回答

0

嘗試顯示在瀏覽器中低圖像的大小,你需要使用,以減少質量imagejpeg功能

// Take value between $quality = (0 < 100) 

imagejpeg($theme_image_enc_little, NULL, $quality);