View file assets/img/cover/index.php

File size: 2.27Kb
<?php
require_once $_SERVER['DOCUMENT_ROOT'].'/system/function.php';
header('Content-type:image/png');

$set = $db->query('SELECT * FROM `set`')->fetch_assoc();
$id = abs(intval($_GET['id']));
$file = $db->query('SELECT * FROM `file` WHERE `id` = '.$id)->fetch_assoc();
if ($file['del'] != 0) {
	$avto = $file['del'] * 86400;
} else {
	$avto = $set['del'] * 86400;
}

if ($file['file']) {
    $filename = H.'/files/'.$file['file'];
} else {
    header('HTTP/1.0 404 Not found');
	exit;
}
$w = 1074;
$h = 480;
$out = imagecreatetruecolor($w, $h);
$bg = imagecolorallocate($out, 93, 128, 166);
imagefill($out, 0, 0, $bg);

$info = getimagesize($filename);

if ($info['mime'] == 'image/jpeg') {
    $img = imagecreatefromjpeg($filename);
} elseif ($info['mime'] == 'image/png') {
    $img = imagecreatefrompng($filename);
} elseif ($file['format'] == 'zip') {
    $img = imagecreatefrompng('zip.png');
} elseif ($file['format'] == 'rar') {
    $img = imagecreatefrompng('rar.png');
} elseif ($file['format'] == 'mp4' or $file['format'] == 'webm') {
    $video = new ffmpeg_movie($filename);
    $frame = $video->getFrame('5');
    $img = $frame->toGDImage();
} elseif ($file['format'] == 'mp3') {
    $img = imagecreatefrompng('mp3.png');
} else {
    $img = imagecreatefrompng('file.png');
}
if ($file['pass'] != 0) {
    $img = imagecreatefrompng('lock.png');
} 
$img_w = imagesx($img);
$img_h = imagesy($img);
$ratio = max($w/$img_w, $h/$img_h);
$img_w = ceil($w / $ratio);
$img_h = ceil($h / $ratio);

$gradient = imagecreatefrompng('gradient.png');
$gr_w = imagesx($gradient);
$gr_h = imagesy($gradient);

$logo = imagecreatefrompng('icon.png');
$logo_w = imagesx($logo);
$logo_h = imagesy($logo);

$font = 'Roboto-Medium.ttf';
putenv('GDFONTPATH='.realpath('.'));
$color = imagecolorallocate($img, 255, 255, 255);

imagecopyresampled($out, $img, 0, 0, 0, 0, $w, $h, $img_w, $img_h);
imagecopyresampled($out, $gradient, 0, 0, 0, 0, $w, $h, $gr_w, $gr_h);
imagettftext($out, 34, 0, 250, 400, $color, $font, $lang['file'].' - '.mb_strimwidth(str_replace($file['format'], '', $file['name']), 0, 22, '...').$file['format']);
imagettftext($out, 22, 0, 250, 440, $color, $font, vremya($file['time']-$avto));
imagecopy($out, $logo, 140, 353, 0, 0, $logo_w, $logo_h);

imagepng($out);
imagedestroy($out);
imagedestroy($logo);
exit;

?>