getimagesizefromstring()函數是PHP中的內置函數,用於從字符串獲取圖像的大小。此函數接受圖像數據作為字符串參數,並確定圖像大小,然後返回尺寸以及文件類型和圖像的高度/寬度。
用法:
array getimagesizefromstring( $imagedata, &$imageinfo )
參數:該函數接受上述和以下描述的兩個參數:
- $filename:這是一個強製參數,它接受圖像數據作為字符串。
- $imageinfo:它是一個可選參數,它允許從圖像文件中提取一些擴展信息,例如將不同的JPG APP標記作為關聯數組。
返回值:此函數返回尺寸以及文件類型和高度/寬度文本字符串。
以下示例程序旨在說明PHP中的getimagesizefromstring()函數:
圖片:

示例1:
<?php 
  
$img =  
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-25.png'; 
   
// Open image as a string 
$data = file_get_contents($img); 
   
// getimagesizefromstring function accepts image data as string 
$info = getimagesizefromstring($data); 
  
// Display the image content 
var_dump($info); 
?>輸出:
array(6) { 
    [0]=> int(667) 
    [1]=> int(184) 
    [2]=> int(3) 
    [3]=> string(24) "width="667" height="184"" 
    ["bits"]=> int(8) 
    ["mime"]=> string(9) "image/png" 
} 
示例2:
<?php 
$img =  
'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-25.png'; 
   
// Open image as a string 
$data = file_get_contents($img); 
  
// getimagesizefromstring function accepts image data as string 
list($width, $height, $type, $attr) = getimagesizefromstring($data); 
   
// Displaying dimensions of the image  
echo "Width of image: " . $width . "<br>";  
     
echo "Height of image: " . $height . "<br>";  
     
echo "Image type: " . $type . "<br>";  
     
echo "Image attribute: " . $attr;  
?>輸出:
Width of image: 667 Height of image: 184 Image type: 3 Image attribute: width="667" height="184"
參考: http://php.net/manual/en/function.getimagesizefromstring.php
相關用法
- PHP cos( )用法及代碼示例
- p5.js sin()用法及代碼示例
- p5.js tan()用法及代碼示例
- PHP tan( )用法及代碼示例
- PHP pos()用法及代碼示例
- PHP key()用法及代碼示例
- p5.js log()用法及代碼示例
- p5.js cos()用法及代碼示例
- d3.js d3.hsl()用法及代碼示例
- PHP each()用法及代碼示例
- PHP each()用法及代碼示例
- p5.js second()用法及代碼示例
注:本文由純淨天空篩選整理自sarthak_ishu11大神的英文原創作品 PHP | getimagesizefromstring() Function。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
