= 4.0.4, PHP 5, PHP 7, PHP 8)imagecreatefromstring — 從字符串中的圖像流新建一圖像說(shuō)明imagecreatefromstring(string $image): resourceimagec">

imagecreatefromstring

(PHP 4 >= 4.0.4, PHP 5, PHP 7, PHP 8)

imagecreatefromstring從字符串中的圖像流新建一圖像

說(shuō)明

imagecreatefromstring(string $image): resource

imagecreatefromstring() 返回一個(gè)圖像標(biāo)識(shí)符,其表達(dá)了從給定字符串得來(lái)的圖像。圖像格式將自動(dòng)檢測(cè),只要 PHP 支持:JPEG,PNG,GIF,WBMP 和 GD2。

參數(shù)

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.';
}
?>

以上例程的輸出類似于:

Output of example : imagecreatefromstring()

參見