Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //--------------------------------------
- if (isset($_GET['url'])) {
- $ch = curl_init();
- //curl_setopt($ch, CURLOPT_HEADER,1);
- curl_setopt($ch, CURLOPT_URL, $_GET['url']);
- curl_setopt($ch, CURLOPT_TIMEOUT, 10);
- curl_setopt($ch, CURLOPT_FOLLOWLOCATION,1);
- curl_setopt($ch, CURLOPT_USERAGENT,
- "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727)");
- curl_setopt($ch,CURLOPT_ENCODING, 1);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
- $teststr = curl_exec($ch);
- if(curl_exec($ch) === false)
- {
- echo 'Ошибка curl: ' . curl_error($ch);
- }
- curl_close($ch);
- header('content-type: image/jpeg');
- $seconds_to_cache = 3600*24*60;
- $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
- header("Expires: $ts");
- header("Pragma: cache");
- header("Cache-Control: max-age=$seconds_to_cache");
- echo $teststr;
- exit();
- }
- //--------------------------------------
- if (isset($_GET['thumb'])) {
- $url = $_GET['thumb'];
- //$time_prev = microtime(true);
- $ch=curl_init();
- curl_setopt($ch, CURLOPT_URL, $url);
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
- curl_setopt($ch, CURLOPT_USERAGENT,
- 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.11 (KHTML, like Gecko)'.
- ' Chrome/20.0.1132.57 Safari/536.11');
- $data=curl_exec($ch);
- curl_close($ch);
- /*$time= microtime(true)-$time_prev;
- echo sprintf("time: %f",$time).'<br/>';
- $time_prev = microtime(true);*/
- list($w,$h)=getimagesize($url);
- /*$time= microtime(true)-$time_prev;
- echo sprintf("time size: %f",$time).'<br/>';
- $time_prev = microtime(true);*/
- if (isset($_GET['nw'])) {
- $nw = $_GET['nw'];
- $nh = $h*($nw/$w);
- }
- else
- if (isset($_GET['nh'])) {
- $nh = $_GET['nh'];
- $nw = $w*($nh/$h);
- } else {
- $nw=300;
- $nh=$h*($nw/$w);
- }
- $thumb=imagecreatetruecolor($nw,$nh);
- $source=imagecreatefromjpeg('data://image/jpeg;base64,'.base64_encode($data));
- imagecopyresampled($thumb,$source,0,0,0,0,$nw,$nh,$w,$h);
- ob_start ();
- imagejpeg ($thumb);
- $image_data = ob_get_contents ();
- ob_end_clean ();
- imagedestroy($source);
- imagedestroy($thumb);
- /*$time= microtime(true)-$time_prev;
- echo sprintf("time resample: %f",$time).'<br/>';
- $time_prev = microtime(true);*/
- //$outstr='data:img/jpeg;base64,'.base64_encode($image_data);
- header('content-type: image/jpeg');
- $seconds_to_cache = 3600*24*60;
- $ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
- header("Expires: $ts");
- header("Pragma: cache");
- header("Cache-Control: max-age=$seconds_to_cache");
- echo $image_data;
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement