GD and Image 函数
在线手册:中文  英文

getimagesizefromstring

(PHP 5 >= 5.4.0)

getimagesizefromstringGet the size of an image from a string

说明

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

Identical to getimagesize() except that getimagesizefromstring() accepts a string instead of a file name as the first parameter.

See the getimagesize() documentation for details on how this function works.

参数

imagedata

The image data, as a string.

imageinfo

See getimagesize().

返回值

See getimagesize().

范例

Example #1 getimagesizefromstring() example

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

// Open as a file
$size_info1 getimagesize($img);

// Or open as a string
$data       file_get_contents($img);
$size_info2 getimagesizefromstring($data);
?>

参见


GD and Image 函数
在线手册:中文  英文

用户评论:

jxwangchao at gmail dot com (2013-04-02 14:59:26)

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);

易百教程