imagecreatefromstring
(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)
imagecreatefromstring — 從字串中的影象流新建一影象
說明
imagecreatefromstring(string
$image
): resourceimagecreatefromstring() 返回一個影象識別符號,其表達了從給定字串得來的影象。影象格式將自動檢測,只要 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.';
}
?>
以上例程的輸出類似於:
參見
- imagecreatefromjpeg() - 由檔案或 URL 建立一個新圖像。
- imagecreatefrompng() - 由檔案或 URL 建立一個新圖像。
- imagecreatefromgif() - 由檔案或 URL 建立一個新圖像。
- imagecreatetruecolor() - 新建一個真彩色影象