Advertisement
Guest User

Untitled

a guest
Apr 20th, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.06 KB | None | 0 0
  1. <?php
  2. //setup
  3. $cache = 1; //1 - OK, 0 - OFF
  4. $url = $_SERVER['QUERY_STRING'];
  5. if (empty($url)) $url = $_SERVER['REDIRECT_QUERY_STRING'];
  6. if ($url == '')
  7. {
  8.     header('HTTP/1.0 404 Not Found');
  9.     die();
  10. }
  11. $mustdel = substr($url, -6) === "&del=1";
  12. if ($mustdel) $url = substr($url, 0, strlen($mustdel) - 7);
  13. $db = new SQLite3('data.db');
  14. $statement = $db->prepare('SELECT real_url FROM proxy_image where my_url = :my_url');
  15. $statement->bindValue(':my_url', "/" . $url);
  16. $result = $statement->execute();
  17. $row = $result->fetchArray();
  18. if ($row == false)
  19. {
  20.     header('HTTP/1.0 404 Not Found');
  21.     die();
  22. }
  23.  
  24. $url = $row['real_url'];
  25. if ($url == '')
  26. {
  27.     header('HTTP/1.0 404 Not Found');
  28.     die();
  29. }
  30.  
  31. $mimeType = 'image/jpeg';
  32. if (strstr($url, '.png') != false) $mimeType = 'image/png';
  33. if (strstr($url, '.gif') != false) $mimeType = 'image/gif';
  34.  
  35. $cachefile = 'images/' . md5($url);
  36. //if(!file_exists($cachefile))
  37. //{
  38. $curl = curl_init($url);
  39. @curl_setopt($curl, CURLOPT_TIMEOUT, 2);
  40. @curl_setopt($curl, CURLOPT_REFERER, $url);
  41. @curl_setopt($curl, CURLOPT_HEADER, 0);
  42. @curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
  43. @curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
  44. @curl_setopt($curl, CURLOPT_BINARYTRANSFER, 1);
  45. @curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
  46. @curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
  47. @curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  48. @curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
  49. @curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)");
  50. if ($cache) curl_setopt($curl, CURLOPT_FILE, fopen($cachefile, "wb"));
  51. $resp = curl_exec($curl);
  52. //echo var_dump($resp); exit;
  53. curl_close($curl);
  54. //echo $url; exit;
  55. //echo var_dump(getimagesize($url)); exit;
  56. header("Content-Type: $mimeType");
  57.  
  58. if ($cache)
  59. {
  60.     uniq_image($resp, $mimeType, $cachefile); //uncomment to mirror&rotate
  61.     if (file_exists($cachefile)) unlink($cachefile);
  62.    
  63.    
  64. }
  65.  
  66. function uniq_image($cachefile, $mimeType, $url)
  67. {
  68.  
  69.     if ($cachefile == false || !@is_array(getimagesize($url)))
  70.     {
  71.         //      echo "no-image"; exit;
  72.         $cachefile = imagecreatetruecolor(600, 600);
  73.         $width = $height = 600;
  74.         $source = $cachefile;
  75.     }
  76.     else
  77.     {
  78.         list($width, $height) = getimagesize($url);
  79.         $source = imagecreatefromstring(file_get_contents($url));
  80.     }
  81.  
  82.     $newwidth = 600;
  83.     $newheight = 600;
  84.  
  85.     // Load
  86.     $thumb = imagecreatetruecolor($newwidth, $newheight);
  87.     //
  88.     // Resize
  89.     imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  90.  
  91.     $img = $thumb;
  92.     //mirror
  93.     imageflip($img, 1); //1 = IMG_FLIP_HORIZONTAL
  94.     $stamp = imagecreatefrompng('mask.png');
  95.  
  96.     imagecopy($img, $stamp, 0, 0, 0, 0, 600, 600);
  97.  
  98.     //save
  99.     switch ($mimeType)
  100.     {
  101.         case 'image/png':
  102.             imagepng($img);
  103.         break;
  104.         case 'image/gif':
  105.             imagegif($img);
  106.         break;
  107.         default:
  108.             imagejpeg($img);
  109.         break;
  110.     }
  111.  
  112.     //close
  113.     imagedestroy($img);
  114. }
  115. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement