Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions Fastimage.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,22 @@ public function load($uri)
{
if ($this->handle) $this->close();

$this->handle = fopen($uri, 'r');
$host = parse_url($uri, PHP_URL_HOST);
$stream_context = @stream_context_create(array(
'http' => array(
'timeout' => 1,
'method' => 'GET',
'user_agent' => (isset($_SERVER['HTTP_USER_AGENT']) && $_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)',
'header' => "Referer: http://$host\r\n"
)
));
$this->handle = fopen($uri, 'rb', null, $stream_context);
}


public function close()
{
if ($this->handle)
if ($this->handle && is_resource($this->handle))
{
fclose($this->handle);
$this->handle = null;
Expand Down Expand Up @@ -72,6 +81,8 @@ public function getType()
return $this->type = 'jpeg';
case chr(0x89).'P':
return $this->type = 'png';
case "RI":
return $this->type = 'webp';
default:
return false;
}
Expand All @@ -94,7 +105,9 @@ private function parseSize()
case 'bmp':
return $this->parseSizeForBMP();
case 'jpeg':
return $this->parseSizeForJPEG();
return $this->parseSizeForJPEG();
case 'webp':
return $this->parseSizeForWEBP();
}

return null;
Expand Down Expand Up @@ -215,7 +228,10 @@ private function getChars($n)
$result = substr($this->str, $this->strpos, $n);
$this->strpos += $n;

return $result;
if (function_exists("mb_convert_encoding"))
return mb_convert_encoding($result, "8BIT", "7BIT");
else
return $result;
}


Expand Down