/** * Генерирует миниатюру и кэширует её. Возвращает имя файла миниатюры. * @param $FileName Исходный файл изображения. * @param int $MaxWidth Максимальная ширина миниатюры. * @param int $MaxHeight Максимальная высота миниатюры. * @param bool $Streech Растягивать ли картинку если заданные размеры больше исходных * @param null $SaveFormat Формат сохранения миниатюры (jpeg, png, gif, wbmp). * @return mixed */ function GetThumb($FileName, $MaxWidth = 0, $MaxHeight = 0, $Streech = false, $SaveFormat = null) { if ($FileName == '') { return 'images/no_image.png'; } elseif (substr($FileName, 0, 7) == 'http://') { return $FileName; } $FileName = RealPath2($FileName); if (isset($SaveFormat)) { $ext = '.' . $SaveFormat; } else { $ext = GetFileExt($FileName); } $tmb_path = System::config('general/tmb_path'); if (!is_dir($tmb_path)) { MkDirRecursive($tmb_path); } $tmb_file = $tmb_path . md5($FileName) . '_' . $MaxWidth . 'x' . $MaxHeight . ($Streech ? '_streech' : '') . $ext; if (!is_file($tmb_file)) { CreateThumb($FileName, $tmb_file, $MaxWidth, $MaxHeight, $Streech, $SaveFormat); } return $tmb_file; }
if (filemtime($rep_cache . $cache_prefix . "." . $obj->FieldName) > time() - $refresh) { if (filesize($rep_cache . $cache_prefix . "." . $obj->FieldName) > 0) { $cache = true; $image = imagesize($obj->FieldName, $Max_thumb); $imagette = rawurlencode(encrypt(rawurldecode($rep_cache_encrypt) . "#fma#" . encrypt($cache_prefix . "." . $obj->FieldName))); } else { $cache = false; } } else { $cache = false; } } else { $cache = false; } if (!$cache) { $image = CreateThumb($obj->FieldName, $cur_nav, $rep_cache . $cache_prefix . ".", $Max_thumb, $suf); if ($image['gene-img'][0] == true) { $imagette = rawurlencode(encrypt(rawurldecode($rep_cache_encrypt) . "#fma#" . encrypt($cache_prefix . "." . $obj->FieldName))); } } } else { $image = imagesize($curn_nav . $obj->FieldName, $Max_thumb); } } else { if ($suf == "png" or $suf == "swf") { $image = imagesize($curn_nav . $obj->FieldName, $Max_thumb); } } $h_i = $image['hauteur'][0]; $h_pi = $image['hauteur'][1]; $w_i = $image['largeur'][0];
/** * Функция управляет загрузкой аватар ($_FILES['upavatar']) * @param $errors * @param $avatar * @param $a_personal * @param $oldAvatarName * @param $oldAvatarPersonal * @param $editmode */ function UserLoadAvatar(&$errors, &$avatar, &$a_personal, $oldAvatarName, $oldAvatarPersonal, $editmode) { $asize = getimagesize($_FILES['upavatar']['tmp_name']); //Проверка формата файла $alloy_mime = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png'); $alloy_exts = array('.gif', '.jpg', '.jpeg', '.png'); if (in_array($_FILES['upavatar']['type'], $alloy_mime) && in_array(strtolower(GetFileExt($_FILES['upavatar']['name'])), $alloy_exts)) { // Удаляем старый аватар if ($editmode && $oldAvatarPersonal == '1') { UnlinkUserAvatarFiles($oldAvatarName); } //Выполняем ресайз, если нужно, и сохраняем аватар в папку персональных аватар $NewName = GenRandomString(12, 'qwertyuiopasdfghjklzxcvbnm'); $ext = strtolower(GetFileExt($_FILES['upavatar']['name'])); $pavatar_dir = System::config('general/personal_avatars_dir'); $max_width = System::config('user/max_avatar_width'); $max_height = System::config('user/max_avatar_height'); if ($asize[0] > $max_width || $asize[1] > $max_height) { CreateThumb($_FILES['upavatar']['tmp_name'], $pavatar_dir . $NewName . $ext, $max_width, $max_height); } else { copy($_FILES['upavatar']['tmp_name'], $pavatar_dir . $NewName . $ext); } // Создаем стандартные уменьшенные копии 24х24 и 64х64 CreateThumb($_FILES['upavatar']['tmp_name'], System::config('general/personal_avatars_dir') . $NewName . '_64x64' . $ext, 64, 64); CreateThumb($_FILES['upavatar']['tmp_name'], System::config('general/personal_avatars_dir') . $NewName . '_24x24' . $ext, 24, 24); $avatar = $NewName . $ext; $a_personal = '1'; } else { $errors[] = 'Неправильный формат файла аватара. Ваш аватар должен быть формата GIF, JPEG или PNG.'; $a_personal = '0'; } }
function massimport($imggal, $descri) { global $MaxSizeImg, $MaxSizeThumb, $ModPath, $ModStart, $NPDS_Prefix; $year = date("Y"); $month = date("m"); $day = date("d"); $hour = date("H"); $min = date("i"); $sec = date("s"); $handle = opendir("modules/{$ModPath}/import"); while ($file = readdir($handle)) { $filelist[] = $file; } closedir($handle); asort($filelist); $i = 1; while (list($key, $file) = each($filelist)) { if (preg_match('#\\.gif|\\.jpg$#i', strtolower($file))) { $filename_ext = strtolower(substr(strrchr($file, "."), 1)); $newfilename = $year . $month . $day . $hour . $min . $sec . "-" . $i . "." . $filename_ext; rename("modules/{$ModPath}/import/{$file}", "modules/{$ModPath}/import/{$newfilename}"); if (function_exists('gd_info') or extension_loaded('gd')) { @CreateThumb($newfilename, "modules/{$ModPath}/import/", "modules/{$ModPath}/imgs/", $MaxSizeImg, $filename_ext); @CreateThumb($newfilename, "modules/{$ModPath}/import/", "modules/{$ModPath}/mini/", $MaxSizeThumb, $filename_ext); } if (sql_query("INSERT INTO " . $NPDS_Prefix . "tdgal_img VALUES ('','{$imggal}','{$newfilename}','{$descri}','','0','0')")) { echo '<p class="font-weight-bold"><i class="fa fa-info-circle"></i> ' . gal_trans("Image ajoutée avec succès") . ' : ' . $file . '</p>'; $i++; } else { echo '<p class="text-danger">' . gal_trans("Impossible d'ajouter l'image en BDD") . '</p>'; @unlink("modules/{$ModPath}/imgs/{$newfilename}"); @unlink("modules/{$ModPath}/mini/{$newfilename}"); } @unlink("modules/{$ModPath}/import/{$newfilename}"); } } }
function AdminGalleryImageRotate() { global $GalleryDir, $ThumbsDir; $turn = $_GET['turn']; $id = SafeEnv($_GET['id'], 11, int); $angle = 0; if ($turn == 'left') { $angle = 90; } else { $angle = 270; } System::database()->Select('gallery', "`id`='{$id}'"); $img = System::database()->FetchRow(); $file_name = $img['file']; $file = $GalleryDir . $file_name; $thumb = $ThumbsDir . $file_name; // Поворачиваем изображение $pic = new TPicture($file); $pic->Rotate($angle); $pic->SaveToFile($file); // Обновляем эскиз if (is_file($thumb)) { unlink($thumb); } CreateThumb($file, $thumb, System::config('gallery/thumb_max_width'), System::config('gallery/thumb_max_height')); Audit('Фотогалерея: Поворот изображения ' . ($turn == 'left' ? 'влево' : 'вправо') . ' "' . $img['title'] . '" (id: ' . $img['id'] . ')'); $back = new Url(GetRefererUrl($_REQUEST['back'])); $back['update'] = SafeDB($_GET['id'], 11, int); // Добавляем / изменяем параметр update GO($back); }
// Создаём уменьшенную копию аватара, если нужно и отправляем пользователю if (isset($_GET['size'])) { switch ($_GET['size']) { case 'small': $avatar_64 = System::config('general/personal_avatars_dir') . GetFileName($avatar, true) . '_64x64' . GetFileExt($avatar); if (is_file($avatar_64)) { CreateThumb($avatar_64)->SendToHTTPClient(); } else { CreateThumb($avatar, $avatar_64, 64, 64)->SendToHTTPClient(); } break; case 'smallest': $avatar_24 = System::config('general/personal_avatars_dir') . GetFileName($avatar, true) . '_24x24' . GetFileExt($avatar); if (is_file($avatar_24)) { CreateThumb($avatar_24)->SendToHTTPClient(); } else { CreateThumb($avatar, $avatar_24, 24, 24)->SendToHTTPClient(); } break; default: CreateThumb($avatar)->SendToHTTPClient(); } } else { CreateThumb($avatar)->SendToHTTPClient(); } if (isset($user_id) && !System::config('user/secure_avatar_upload')) { System::user()->UpdateAvatarData($user_id); } // Восстанавливаем Referer System::user()->Def('REFERER', $_SERVER['HTTP_REFERER']); exit;
function bikinThumbs($id,$file){ $nfile = WEB_PATH."/images/galery/$id/$file"; #echo "nfile : $nfile<br>"; $dfile = WEB_PATH."/images/galery/$id/thumbs_$file"; #echo "dfile : $dfile<br>"; if(file_exists($nfile)){ if(CreateThumb($nfile,150,100,$dfile)){ return true; }else{ return false; } } }
/** * Возвращает URL эскиза изображения или иконки файла * * @param $dir * @param $md5 * @param $filename * @param int $width * @param int $height * @internal param $type * @return string */ public function GetThumbUrl($dir, $md5, $filename, $width = 100, $height = 100) { $path = RealPath2(DIR_FILES . '/' . $dir); $url_path = URL_FILES . '/' . RealPath2($dir); if (substr($url_path, -1) == '/') { $url_path = substr($url_path, 0, -1); } $ext = strtolower(GetFileExt($filename, true)); if (in_array($ext, $this->allowedImages)) { $thumb = '/.thumbs/' . $md5 . '_' . $width . '_' . $height . '.jpg'; if (is_file($path . $thumb)) { return $url_path . $thumb; } CreateThumb($path . '/' . $filename, $path . $thumb, $width, $height, false, 'jpeg'); return $url_path . $thumb; } else { if ($ext != '' && is_file(DIR_ICONS . '/' . $ext . '.png')) { return URL_ICONS . '/' . $ext . '.png'; } else { return URL_ICONS . '/' . 'none.png'; } } }
function AddImgs($imgscat, $newcard1, $newdesc1, $newcard2, $newdesc2, $newcard3, $newdesc3, $newcard4, $newdesc4, $newcard5, $newdesc5, $user_connecte) { global $language, $MaxSizeImg, $MaxSizeThumb, $ModPath, $ModStart, $NPDS_Prefix, $ThisFile, $adminmail, $nuke_url, $notif_admin; include_once "modules/upload/lang/upload.lang-{$language}.php"; include_once "modules/upload/clsUpload.php"; $newdesc1 = $newdesc1 . gal_trans(" proposé par ") . $user_connecte; $newdesc2 = $newdesc2 . gal_trans(" proposé par ") . $user_connecte; $newdesc3 = $newdesc3 . gal_trans(" proposé par ") . $user_connecte; $newdesc4 = $newdesc4 . gal_trans(" proposé par ") . $user_connecte; $newdesc5 = $newdesc5 . gal_trans(" proposé par ") . $user_connecte; $year = date("Y"); $month = date("m"); $day = date("d"); $hour = date("H"); $min = date("i"); $sec = date("s"); echo '<h4 class="breadcrumb"><a href="' . $ThisFile . '">' . gal_trans("Accueil") . '</a></h4>'; echo '<p>' . gal_trans("Proposer des images") . '</p>'; echo "<ul>"; $soumission = false; $i = 1; while ($i <= 5) { $img = "newcard{$i}"; $tit = "newdesc{$i}"; if (!empty(${$img})) { $newimg = stripslashes(removeHack(${$img})); if (!empty(${$tit})) { $newtit = addslashes(removeHack(${$tit})); } else { $newtit = ""; } $upload = new Upload(); $upload->maxupload_size = 200000 * 100; $origin_filename = trim($upload->getFileName("newcard" . $i)); $filename_ext = strtolower(substr(strrchr($origin_filename, "."), 1)); if ($filename_ext == "jpg" or $filename_ext == "gif") { $newfilename = $year . $month . $day . $hour . $min . $sec . "-" . $i . "." . $filename_ext; if ($upload->saveAs($newfilename, "modules/{$ModPath}/imgs/", "newcard" . $i, true)) { if (function_exists('gd_info') or extension_loaded('gd')) { @CreateThumb($newfilename, "modules/{$ModPath}/imgs/", "modules/{$ModPath}/imgs/", $MaxSizeImg, $filename_ext); @CreateThumb($newfilename, "modules/{$ModPath}/imgs/", "modules/{$ModPath}/mini/", $MaxSizeThumb, $filename_ext); } if (sql_query("INSERT INTO " . $NPDS_Prefix . "tdgal_img VALUES ('','{$imgscat}','{$newfilename}','{$newtit}','','0','1')")) { echo "<li>" . gal_trans("Photo envoyée avec succès, elle sera traitée par le webmaster") . " : {$origin_filename}</li>"; $soumission = true; } else { echo "<li><span class=\"text-danger\">" . gal_trans("Impossible d'ajouter l'image en BDD") . " : {$origin_filename}</span></li>"; @unlink("modules/{$ModPath}/imgs/{$newfilename}"); @unlink("modules/{$ModPath}/mini/{$newfilename}"); } } else { echo "<li><span class=\"text-danger\">" . $upload->errors . "</span></li>"; } } else { if ($filename_ext != "") { echo "<li><span class=\"text-danger\">" . gal_trans("Ce fichier n'est pas un fichier jpg ou gif") . " : {$origin_filename}</span></li>"; } } } $i++; } echo "</ul>"; if ($notif_admin and $soumission) { $subject = gal_trans("Nouvelle soumission de Photos"); $message = gal_trans("Des photos viennent d'être proposées dans la galerie photo du site ") . $nuke_url . gal_trans(" par ") . $user_connecte; send_email($adminmail, $subject, $message, "", true, "html"); } }
function LoadImage($PostName, $Dir, $ThumbsDir, $MaxWidth, $MaxHeight, $Default, &$Error, $CreateThumbs = true, $OriginalOptimization = false, $OriginalMaxWidth = 800, $OriginalMaxHeight = 600) { $Error = false; if ($Default == 'no_image/no_image.png') { $Default = ''; } $Dir = RealPath2($Dir); $ThumbsDir = RealPath2($ThumbsDir); $alloy_mime = array('image/gif', 'image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'application/octet-stream'); $alloy_exts = array('.gif', '.jpg', '.jpeg', '.png'); if (isset($_FILES[$PostName]) && is_file($_FILES[$PostName]['tmp_name'])) { if (in_array($_FILES[$PostName]['type'], $alloy_mime) && in_array(strtolower(GetFileExt($_FILES[$PostName]['name'])), $alloy_exts)) { $file_name = Translit4Url($_FILES[$PostName]['name']); if (!is_dir($Dir)) { mkdir($Dir, 0777); } $ext = GetFileExt($file_name); $name = GetFileName($file_name, true); $i = 1; while (is_file($Dir . '/' . $file_name)) { $i++; $file_name = $name . '_' . $i . $ext; } $FileName = $Dir . '/' . $file_name; $ThumbFileName = $ThumbsDir . '/' . $file_name; if (!$OriginalOptimization) { copy($_FILES[$PostName]['tmp_name'], $FileName); } else { CreateThumb($_FILES[$PostName]['tmp_name'], $FileName, $OriginalMaxWidth, $OriginalMaxHeight); } if ($CreateThumbs) { if (!is_dir($ThumbsDir)) { mkdir($ThumbsDir, 0777); } CreateThumb($FileName, $ThumbFileName, $MaxWidth, $MaxHeight); } $result = $file_name; } else { $Error = true; return RealPath2(SafeEnv($Default, 255, str)); } } else { $result = RealPath2(SafeEnv($Default, 255, str)); } return $result; }
function CreateAppleIcon($source, $size = 57, $radius = 20) { $image = CreateThumb($source, $size, $size); ApplyGlow($image); ApplyRoundedCorners($image, $radius); return $image; }