php5.4以下模拟getimagesizefromstring
html5上传图片时可用php://input的数据流来运作.
如果要得到图片信息,那只有getimagesize($filename),再打一次刚关闭的文件.
php里有一个getimagesizefromstring,但是要>=php5.4,但目前还没服务器还没用上这么高版本的php.
作为一个效率癖,这是不被允许的,有直接操纵数据流的方法吗?
当然, stream_register_wrapper — 注册一个用 PHP 类实现的 URL 封装协议
php代码
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_seek($offset, $whence){ $l = strlen($this->imgStream); $p = &$this->position; switch($whence){ case SEEK_SET: $newPos = $offset; break; case SEEK_CUR: $newPos = $p + $offset; break; case SEEK_END: $newPos = $l + $offset; break; default: return false; } $ret = ($newPos >= 0 && $newPos <= $l); if($ret) $p = $newPos; return $ret; } 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);
로그인 후 복사
方法二
$file_path = 'http://www.baidu.com/img/shouye_b5486898c692066bd2cbaeda86d74448.gif'; $stream = file_get_contents($file_path); print_r(getimagesize("data://text/plain;base64," . base64_encode($stream))); $new_img = imagecreatefromgif("data://text/plain;base64," . base64_encode($stream)); //或者 $new_img = imagecreatefromstring($stream); print_r($new_img); imagejpeg($new_img, 'E:\WEB\uploads\test.jpg', 100);
로그인 후 복사
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사
R.E.P.O. 에너지 결정과 그들이하는 일 (노란색 크리스탈)
2 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
Repo : 팀원을 부활시키는 방법
4 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
헬로 키티 아일랜드 어드벤처 : 거대한 씨앗을 얻는 방법
3 몇 주 전
By 尊渡假赌尊渡假赌尊渡假赌
스플릿 소설을이기는 데 얼마나 걸립니까?
3 몇 주 전
By DDD
R.E.P.O. 파일 저장 위치 : 어디에 있고 그것을 보호하는 방법은 무엇입니까?
3 몇 주 전
By DDD

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제
Gmail 이메일의 로그인 입구는 어디에 있나요?
7321
9


자바 튜토리얼
1625
14


Cakephp 튜토리얼
1349
46


라라벨 튜토리얼
1261
25


PHP 튜토리얼
1209
29

