PHP 8.3.4 Released!

getimagesizefromstring

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

getimagesizefromstringRécupère la taille d'une image depuis une chaîne

Description

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

Identique à la fonction getimagesize() excepté le fait que la fonction getimagesizefromstring() accepte une chaîne au lieu d'un nom de fichier comme premier paramètre.

Voir la documentation sur la fonction getimagesize() pour plus de détails sur la façon dont cette fonction marche.

Liste de paramètres

string

Les données de l'image, sous la forme d'une chaîne.

image_info

Voir la fonction getimagesize().

Valeurs de retour

Voir la fonction getimagesize().

Exemples

Exemple #1 Exemple avec getimagesizefromstring()

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

// Ouverture via un fichier
$size_info1 = getimagesize($img);

// Ouverture via une chaîne
$data = file_get_contents($img);
$size_info2 = getimagesizefromstring($data);
?>

Voir aussi

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