Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //setup
- $cache = 1; //1 - OK, 0 - OFF
- $url = $_SERVER['QUERY_STRING'];
- if (empty($url)) $url = $_SERVER['REDIRECT_QUERY_STRING'];
- if ($url == '')
- {
- header('HTTP/1.0 404 Not Found');
- die();
- }
- $mustdel = substr($url, -6) === "&del=1";
- if ($mustdel) $url = substr($url, 0, strlen($mustdel) - 7);
- $db = new SQLite3('data.db');
- $statement = $db->prepare('SELECT real_url FROM proxy_image where my_url = :my_url');
- $statement->bindValue(':my_url', "/" . $url);
- $result = $statement->execute();
- $row = $result->fetchArray();
- if ($row == false)
- {
- header('HTTP/1.0 404 Not Found');
- die();
- }
- $url = $row['real_url'];
- if ($url == '')
- {
- header('HTTP/1.0 404 Not Found');
- die();
- }
- $mimeType = 'image/jpeg';
- if (strstr($url, '.png') != false) $mimeType = 'image/png';
- if (strstr($url, '.gif') != false) $mimeType = 'image/gif';
- $cachefile = 'images/' . md5($url);
- //if(!file_exists($cachefile))
- //{
- $curl = curl_init($url);
- @curl_setopt($curl, CURLOPT_TIMEOUT, 2);
- @curl_setopt($curl, CURLOPT_REFERER, $url);
- @curl_setopt($curl, CURLOPT_HEADER, 0);
- @curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
- @curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
- @curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
- @curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
- @curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
- @curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- @curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
- @curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
- if ($cache) curl_setopt($curl, CURLOPT_FILE, fopen($cachefile, "wb"));
- $resp = curl_exec($curl);
- //echo var_dump($resp); exit;
- curl_close($curl);
- //echo $url; exit;
- //echo var_dump(getimagesize($url)); exit;
- header("Content-Type: $mimeType");
- if ($cache)
- {
- uniq_image($resp, $mimeType, $cachefile); //uncomment to mirror&rotate
- if (file_exists($cachefile)) unlink($cachefile);
- }
- function uniq_image($cachefile, $mimeType, $url)
- {
- if ($cachefile == false || !@is_array(getimagesize($url)))
- {
- // echo "no-image"; exit;
- $cachefile = imagecreatetruecolor(600, 600);
- $width = $height = 600;
- $source = $cachefile;
- }
- else
- {
- list($width, $height) = getimagesize($url);
- $source = imagecreatefromstring(file_get_contents($url));
- }
- $newwidth = 600;
- $newheight = 600;
- // Load
- $thumb = imagecreatetruecolor($newwidth, $newheight);
- //
- // Resize
- imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
- $img = $thumb;
- //mirror
- imageflip($img, 1); //1 = IMG_FLIP_HORIZONTAL
- $stamp = imagecreatefrompng('mask.png');
- imagecopy($img, $stamp, 0, 0, 0, 0, 600, 600);
- //save
- switch ($mimeType)
- {
- case 'image/png':
- imagepng($img);
- break;
- case 'image/gif':
- imagegif($img);
- break;
- default:
- imagejpeg($img);
- break;
- }
- //close
- imagedestroy($img);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement