有base64格式的拖曳图像($theme_image_enc
和$theme_image_enc_little
)。现在我想让第二张图像($theme_image_enc_little
)尺寸变小,如15kb。怎么办?
$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 :(得分:0)
尝试使用imagejpeg
功能
// Take value between $quality = (0 < 100)
imagejpeg($theme_image_enc_little, NULL, $quality);