0
필자는 원격으로 호스팅 된 JPG의 크기 (너비와 높이)를 전체 (단지 처음 10K)로 다운로드하지 않고도 얻을 수있는 PHP 스크립트를 작성했습니다.디스크에 쓰지 않고 부분 추출로 JPG 치수 가져 오기
이 문제는 파일에 부분 다운로드를 작성한 다음 해당 파일을 읽고 필요한 정보를 추출하는 것입니다 (getImageSize
사용).
나는 이것이 디스크에 쓰지 않고 다운 될 수 있다는 것을 알고 있지만 어떻게해야할지 모르겠다.
누구나 제안/해결책이 있습니까?
function remoteImage($url){
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_RANGE, "0-10240");
$fn = "partial.jpg";
$raw = curl_exec($ch);
$result = array();
if(file_exists($fn)){
unlink($fn);
}
if ($raw !== false) {
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status == 200 || $status == 206) {
$result["w"] = 0;
$result["h"] = 0;
$fp = fopen($fn, 'x');
fwrite($fp, $raw);
fclose($fp);
$size = getImageSize($fn);
if ($size===false) {
// Cannot get file size information
} else {
// Return width and height
list($result["w"], $result["h"]) = $size;
}
}
}
curl_close ($ch);
return $result;
}
이 이어질 내 원래 질문은, here - and might be helpful입니다 :
여기에 내 원래의 코드입니다.
당신이이 사람의 솔루션을 시도했다? http://www.php.net/manual/en/function.getimagesize.php#88793 –