php – 如何保存从imagecreatefromstring()函数创建的图像?

前端之家收集整理的这篇文章主要介绍了php – 如何保存从imagecreatefromstring()函数创建的图像?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
这是我的代码
$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'
       . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'
       . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'
       . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';
$data = base64_decode($data);

$im = imagecreatefromstring($data);
if ($im !== false) {
    header('Content-Type: image/png');
    imagepng($im);
    imagedestroy($im);

}
else {
    echo 'An error occurred.';
}

我想将以这种方式生成的图像保存到目录中.我该如何做?

这是imagepng的正确语法:
imagepng($im,"/path/where/you/want/save/the/png.png");

根据PHP manual

bool imagepng ( resource $image [,string $filename [,int $quality [,
int $filters ]]] )

filename – The path to save the file to.

If not set or NULL,the raw image stream will be outputted directly.

原文链接:https://www.f2er.com/php/139742.html

猜你在找的PHP相关文章