在php中将base64转换为图像大小调整和编码

在php中将base64转换为图像大小调整和编码,php,jpeg,Php,Jpeg,我使用html5文件api在浏览器中预览图像,然后使用ajax将其保存为base64字符串 我需要降低质量以调整图像大小 <?php $img = $_POST['img']; $i = explode(",",$img); $img = $i[1]; $img = imagecreatefromstring[$img]; $rimg = imagejpeg($img,XXXXXXX, 60); ?> xxx=> how could I turned it back t

我使用html5文件api在浏览器中预览图像,然后使用ajax将其保存为base64字符串

我需要降低质量以调整图像大小

<?php

$img = $_POST['img'];
$i = explode(",",$img);

$img = $i[1];
$img = imagecreatefromstring[$img];
$rimg = imagejpeg($img,XXXXXXX, 60);

?>

xxx=> how could I turned it back to base64?

xxx=>我怎样才能将其返回base64?
提前感谢。

来自

或者保存到文件中,然后以二进制流的形式加载文件,以64位二进制为基数并删除该文件

 /*
 * imageXXX() only has two options, save as a file, or send to the browser.
 * It does not provide you the oppurtunity to manipulate the final GIF/JPG/PNG file stream
 * So I start the output buffering, use imageXXX() to output the data stream to the browser,
 * get the contents of the stream, and use clean to silently discard the buffered contents.
 */
ob_start();

switch ($image_type)
{
    case 1: imagegif($tmp); break;
    case 2: imagejpeg($tmp, NULL, 100);  break; // best quality
    case 3: imagepng($tmp, NULL, 0); break; // no compression
    default: echo ''; break;
}

$final_image = ob_get_contents();

ob_end_clean();

return $final_image;