downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

image_type_to_extension> <getimagesize
[edit] Last updated: Fri, 17 May 2013

view this page in

getimagesizefromstring

(PHP 5 >= 5.4.0)

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

Description

array getimagesizefromstring ( string $imagedata [, array &$imageinfo ] )

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

imagedata

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

imageinfo

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 add a note User Contributed Notes getimagesizefromstring - [1 notes]
up
-1
jxwangchao at gmail dot com
1 month ago
php<5.4 getimagesizefromstring
class getImgStream{
 
     private $imgStream;
     private $position;
 
     function stream_open($path, $mode, $options, &$opened_path){
         $url = parse_url($path);
         $this->imgStream = $GLOBALS[$url["host"]];
         $this->position = 0;
         return true;
     }
 
     function stream_read($count){
         $ret = substr($this->imgStream, $this->position, $count);
         $this->position += strlen($ret);
         return $ret;
     }
 
     function stream_stat(){
         //maxmemory: 5 * 1024 * 1024;
         $fp = fopen("php://temp/maxmemory:5242880", 'r+');
         fwrite($fp, $this->imgStream);
         $fstat = fstat($fp);
         fclose($fp);
         return $fstat;
     }
 
     function stream_eof(){
         return $this->position >= strlen($this->imgStream);
     }
 
     function stream_tell(){
         return $this->position;
     }
 
     function stream_close(){
         unset($this->imgStream, $this->position);
     }
 
 }
 
 $file_path = 'http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif';
 $stream = file_get_contents($file_path);
 
 stream_wrapper_register("image", "getImgStream");
 
 print_r(getimagesize('image://stream'));
 $new_img = imagecreatefromgif('image://stream');//或者$new_img = imagecreatefromstring($stream);
 print_r($new_img);
 imagejpeg($new_img, 'E:\WEB\uploads\test.jpg', 100);

 
show source | credits | sitemap | contact | advertising | mirror sites