Размер файла: 1.94Kb
- <?php
- // error_reporting(0); // это надо убрать и исправить ошибки!
- require '../system/inc/core.php';
- $inp = 'files/' . $_GET['file'] . ''; //Путь к файлу
- if((strpos($_GET['file'], "..")!==FALSE) | !$_GET['file']){
- header("HTTP/1.0 404 Not Found");
- header("Status: 404 Not Found");
- $inp = "img/700.png"; //Путь к файлу, который будет выведен, если изображения не существует
- }
- if(!file_exists($inp)|is_dir($inp)){
- header("HTTP/1.0 404 Not Found");
- header("Status: 404 Not Found");
- $inp = "img/700.png"; //Путь к файлу, который будет выведен, если изображения не существует
- }
- $wid = 100; //Размер превью в пикселах
- $path_info = pathinfo($inp);
- if (strtolower($path_info[extension]) == 'jpg' | strtolower($path_info[extension]) == 'jpeg') {
- $res = imagecreatefromjpeg($inp);
- } else {
- if (strtolower($path_info[extension]) == 'png') {
- $res = imagecreatefrompng($inp);
- } else {
- if (strtolower($path_info[extension]) == 'gif') {
- $res = imagecreatefromgif($inp);
- } else {
- header("HTTP/1.0 404 Not Found");
- header("Status: 404 Not Found");
- $inp = "img/700.png";
- $res = imagecreatefromjpeg($inp);
- }
- }
- }
- $prop = getimagesize($inp);
- $newWidth = $wid;
- $newHeight = $prop[1]*($wid/$prop[0]);
- $tmp = imagecreatetruecolor($newWidth,$newWidth);
- imagealphablending($tmp, false);
- imagesavealpha($tmp, true);
- imagefill($tmp, 0, 0, IMG_COLOR_TRANSPARENT);
- if ($newWidth > $newHeight) {
- imagecopyresampled($tmp, $res, -($newWidth - $newHeight), 0, 0, 0, $newWidth + 2 * ($newWidth - $newHeight), $newHeight + ($newWidth - $newHeight), $prop[0], $prop[1]);
- } else {
- imagecopyresampled($tmp, $res, 0, ($newWidth - $newHeight) / 2, 0, 0, $newWidth, $newHeight, $prop[0], $prop[1]);
- }
- header('Content-Type: image/png');
- imagepng($tmp);
- imagedestroy($tmp);