從字串中的影象流新建一影象

imagecreatefromstring

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

imagecreatefromstring從字串中的影象流新建一影象

說明

imagecreatefromstring(string $image): resource

imagecreatefromstring() 返回一個影象識別符號,其表達了從給定字串得來的影象。影象格式將自動檢測,只要 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.';
}
?>

以上例程的輸出類似於:

Output of example : imagecreatefromstring()

參見

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *