PHP 8.3.4 Released!

getimagesizefromstring

(PHP 5 >= 5.4.0, PHP 7, PHP 8)

getimagesizefromstring画像の大きさを文字列から取得する

説明

getimagesizefromstring(string $string, array &$image_info = null): array|false

getimagesize() と似ていますが、 getimagesizefromstring() の最初のパラメータはファイル名ではなく文字列となります。

この関数の挙動の詳細については getimagesize() のドキュメントを参照ください。

パラメータ

string

文字列で表した画像データ。

image_info

getimagesize() を参照ください。

戻り値

getimagesize() を参照ください。

例1 getimagesizefromstring() の例

<?php
$img
= '/path/to/test.png';

// ファイルとして開く
$size_info1 = getimagesize($img);

// あるいは、文字列として開く
$data = file_get_contents($img);
$size_info2 = getimagesizefromstring($data);
?>

参考

add a note

User Contributed Notes 2 notes

up
21
imageman
10 years ago
getimagesizefromstring function for < 5.4

<?php
if (!function_exists('getimagesizefromstring')) {
function
getimagesizefromstring($string_data)
{
$uri = 'data://application/octet-stream;base64,' . base64_encode($string_data);
return
getimagesize($uri);
}
}
?>
up
3
sarah at anigel dot net
10 years ago
Just a quick comment on the solution by imageman for versions < 5.4 you will need to enable allow_url_fopen in order to use the data wrapper.
To Top