function get_thumb($post_id, $topic_id)
{
$cMaxWidth = 90; //размер тумбы))
$tText = DB()->fetch_row("SELECT post_text FROM " . BB_POSTS_TEXT . " WHERE post_id = $post_id");
preg_match_all('/\[img=right\](.*?)\[\/img\]/i', $tText['post_text'], $tPaImg, PREG_SET_ORDER);
preg_match_all('/\[img=left\](.*?)\[\/img\]/i', $tText['post_text'], $tPaImg2, PREG_SET_ORDER);
preg_match_all('/\[img\](.*?)\[\/img\]/i', $tText['post_text'], $tPaImg3, PREG_SET_ORDER);
$url = '';
if (@$tPaImg[0][1])
{
$url = $tPaImg[0][1];
}
elseif (@$tPaImg2[0][1])
{
$url = $tPaImg2[0][1];
}
elseif (@$tPaImg3[0][1])
{
$url = $tPaImg3[0][1];
}
$url=str_replace("http://ваш.домен","путь до каталога вашего трекера",$url);
if(!empty($url))
{
$imgs = @file_get_contents($url, 0, stream_context_create( array('http' => array('timeout' => 60)) ));
if ($imgs != null)
{
mt_srand(time()+microtime()*rand(1,999));
$filename = 'pictures/posters/'.md5('topic_'.$topic_id).'_original.jpg';
file_put_contents($filename,$imgs);
$iInfo = getimagesize($filename);
list($poster_width, $poster_height) = getimagesize($filename);
switch ($iInfo['mime'])
{
case 'image/png':
$cImage = imagecreatefrompng($filename);
break;
case 'image/gif':
$cImage = imagecreatefromgif($filename);
break;
case 'image/jpeg':
$cImage = imagecreatefromjpeg($filename);
break;
default:
$cImage = false;
}
if($cImage)
{
$thumb_width = $cMaxWidth;
$thumb_height = ($poster_height*$cMaxWidth)/$poster_width;
$tImage = imagecreatetruecolor($thumb_width, $thumb_height);
imagecopyresampled($tImage, $cImage, 0, 0, 0, 0, $thumb_width, $thumb_height, $poster_width, $poster_height);
imagealphablending($tImage, true);
imagesavealpha($tImage, true);
imagejpeg($tImage, 'pictures/posters/'.md5('topic_'.$topic_id).'.jpg', 85);
imagedestroy($tImage);
imagedestroy($cImage);
DB()->query("UPDATE " . BB_TOPICS . " SET topic_image = '" . (md5('topic_'.$topic_id)) . "' WHERE topic_id=$topic_id");
}
}
}
}