Advertisement
cyber01

Untitled

Nov 10th, 2017
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.78 KB | None | 0 0
  1. <?
  2. error_reporting(E_ALL);
  3.  
  4. define("STRING", "WWW.site.RU".iconv("utf-8","cp1251"," (Сайт)"));
  5. function toUnicodeEntites($text, $from="w")
  6. {   $text = convert_cyr_string($text, $from, "i");
  7.     //print $text;
  8.     $uni = "";
  9.     $len=strlen($text);
  10.     for ($i=0;  $i<$len; $i++)
  11.     {   $char = $text{$i};
  12.         $code = ord($char);
  13.         $uni .= ($code>175)? "&#" . (1040+($code-176)) . ";" : $char;
  14.     }
  15.     return $uni;
  16. }
  17. function thumb($path,$x,$y=0)
  18. {   $t=@getimagesize ($path) or die('К сожалению, эта фотография не может быть отображена!');
  19.     $with=$t[0];
  20.     if ($x == "")
  21.     $x = $with;
  22.     $height=$t[1];
  23.     switch ($t[2])
  24.     {   case 1:
  25.         $type='GIF';
  26.         $img=imagecreatefromgif($path);
  27.         break;
  28.         case 2:
  29.         $type='JPEG';
  30.         $img=imagecreatefromjpeg($path);
  31.         break;
  32.         case 3:
  33.         $type='PNG';
  34.         $img=imagecreatefrompng($path);
  35.         break;
  36.     }
  37.     if($y==0)
  38.     {$y=$x*($height/$with);}
  39.     header("Content-type: image/".$type);
  40.     $thumb=ImageCreateTrueColor($x,$y);
  41.     imagecopyresampled($thumb,$img,0,0,0,0,$x,$y,$with,$height);
  42.     //Àäðåñ ñàéòà
  43.     if ($x > 400 and STRING != "")
  44.     {   $path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['PHP_SELF'];
  45.         $path = preg_replace ("/(^.*)(thumb.php)(.*)/", "\\1", $path);
  46.         $config_font = "5";
  47.         $string = STRING;
  48.         $black = imagecolorallocate ($thumb, 0, 0, 0);
  49.         $white = imagecolorallocate ($thumb, 255, 0, 0);
  50.         $x = 10;
  51.         $y = $y-5;
  52.         if (function_exists("imagettftext"))
  53.         {imagettftext($thumb, 22, 0, $x, $y-10, $white, $path."arialbi.ttf", toUnicodeEntites($string));}
  54.         else {imagestring($thumb, "5",$x, $y-20, $string, $white);}
  55.         //
  56.     }
  57.     $thumb=imagejpeg($thumb);
  58.     return $thumb;}
  59. if (isset ($_GET['id'])) $id = $_GET['id'];
  60. if(isset ($_GET['w'])) $w = $_GET['w'];else $w = "";
  61. if ($id){echo thumb($id,$w); echo $path;}
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement