= 4.0.4, PHP 5, PHP 7, PHP 8)imagecreatefromstring — 從字符串中的圖像流新建一圖像說明imagecreatefromstring(string $image): resourceimagec">
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
imagecreatefromstring — 從字符串中的圖像流新建一圖像
$image
): resourceimagecreatefromstring() 返回一個(gè)圖像標(biāo)識(shí)符,其表達(dá)了從給定字符串得來的圖像。圖像格式將自動(dòng)檢測,只要 PHP 支持:JPEG,PNG,GIF,WBMP 和 GD2。
image
A string containing the image data.
An image resource will be returned on success. false
is returned if
the image type is unsupported, the data is not in a recognised format,
or the image is corrupt and cannot be loaded.
示例 #1 imagecreatefromstring() example
<?php
$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.';
}
?>
以上例程的輸出類似于: