mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-03 01:39:24 +02:00
Make better portrait thumbnails
This commit is contained in:
parent
57f923936a
commit
2ab1c49bb0
4 changed files with 95 additions and 121 deletions
|
@ -1783,7 +1783,6 @@ function im_resize($file_src, $file_dest, $wd, $hd, $q = 80) {
|
|||
}
|
||||
|
||||
function im_resizeV2($file_src, $file_dest, $wd, $hd, $q = 80) {
|
||||
return scaleUpImage($file_src, $file_dest, $wd, $hd);
|
||||
|
||||
//_error_log("im_resizeV2: $file_src, $file_dest, $wd, $hd, $q");
|
||||
$newImage = im_resize($file_src, $file_dest, $wd, $hd, 100);
|
||||
|
@ -1880,7 +1879,15 @@ function scaleUpImage($file_src, $file_dest, $wd, $hd) {
|
|||
$old_y = imageSY($src_img);
|
||||
|
||||
$sizes = scaleUpAndMantainAspectRatioFinalSizes($wd, $old_x, $hd, $old_y);
|
||||
|
||||
/*
|
||||
if($wd!==200){
|
||||
echo "<h1>Original</h1>X={$old_x} Y={$old_y}";
|
||||
echo "<h1>Destination</h1>X={$wd} Y={$hd}";
|
||||
echo '<h1>Results</h1>';
|
||||
var_dump($sizes);exit;
|
||||
}
|
||||
*
|
||||
*/
|
||||
$thumb_w = $sizes['w'];
|
||||
$thumb_h = $sizes['h'];
|
||||
|
||||
|
@ -3899,7 +3906,7 @@ function convertImageIfNotExists($source, $destination, $width, $height, $scaleU
|
|||
_error_log("convertImageToRoku: source does not exists");
|
||||
return false;
|
||||
}
|
||||
if (file_exists($destination)) {
|
||||
if (file_exists($destination) && filesize($destination) > 1024) {
|
||||
$sizes = getimagesize($destination);
|
||||
if ($sizes[0] < $width || $sizes[1] < $height) {
|
||||
_error_log("convertImageIfNotExists: file is smaller " . json_encode($sizes));
|
||||
|
|
|
@ -4179,24 +4179,8 @@ if (!class_exists('Video')) {
|
|||
$obj->thumbsGif = $gifSource['url'];
|
||||
}
|
||||
if (file_exists($jpegPortraitSource['path'])) {
|
||||
// create thumbs
|
||||
if (!file_exists($jpegPortraitThumbs['path']) && filesize($jpegPortraitSource['path']) > 1024) {
|
||||
_error_log("Resize JPG 1 {$jpegPortraitSource['path']}, {$jpegPortraitThumbs['path']}");
|
||||
if (!empty($advancedCustom->useFFMPEGToGenerateThumbs)) {
|
||||
im_resizeV3($jpegPortraitSource['path'], $jpegPortraitThumbs['path'], $advancedCustom->thumbsWidthPortrait, $advancedCustom->thumbsHeightPortrait);
|
||||
} else {
|
||||
im_resizeV2($jpegPortraitSource['path'], $jpegPortraitThumbs['path'], $advancedCustom->thumbsWidthPortrait, $advancedCustom->thumbsHeightPortrait);
|
||||
}
|
||||
}
|
||||
// create thumbs
|
||||
if (!file_exists($jpegPortraitThumbsSmall['path']) && filesize($jpegPortraitSource['path']) > 1024) {
|
||||
_error_log("Resize JPG 2 {$jpegPortraitSource['path']}, {$jpegPortraitThumbsSmall['path']}");
|
||||
if (!empty($advancedCustom->useFFMPEGToGenerateThumbs)) {
|
||||
im_resizeV3($jpegPortraitSource['path'], $jpegPortraitThumbsSmall['path'], $advancedCustom->thumbsWidthPortrait, $advancedCustom->thumbsHeightPortrait);
|
||||
} else {
|
||||
im_resizeV2($jpegPortraitSource['path'], $jpegPortraitThumbsSmall['path'], $advancedCustom->thumbsWidthPortrait, $advancedCustom->thumbsHeightPortrait, 5);
|
||||
}
|
||||
}
|
||||
convertImageIfNotExists($jpegPortraitSource['path'], $jpegPortraitThumbs['path'], $advancedCustom->thumbsWidthPortrait, $advancedCustom->thumbsHeightPortrait, true);
|
||||
convertImageIfNotExists($jpegPortraitThumbsSmall['path'], $jpegPortraitThumbsSmall['path'], $advancedCustom->thumbsWidthPortrait/2, $advancedCustom->thumbsHeightPortrait/2, true);
|
||||
} else {
|
||||
if ($type == "article") {
|
||||
$obj->posterPortrait = "" . getCDN() . "view/img/article_portrait.png";
|
||||
|
@ -4229,26 +4213,8 @@ if (!class_exists('Video')) {
|
|||
if (file_exists($jpegSource['path'])) {
|
||||
$obj->poster = $jpegSource['url'];
|
||||
$obj->thumbsJpg = $thumbsSource['url'];
|
||||
// create thumbs
|
||||
if (!file_exists($thumbsSource['path']) && filesize($jpegSource['path']) > 1024) {
|
||||
if (!empty($advancedCustom->useFFMPEGToGenerateThumbs)) {
|
||||
//_error_log("Resize JPG 3 useFFMPEGToGenerateThumbs {$jpegSource['path']}, {$thumbsSource['path']}");
|
||||
im_resizeV3($jpegSource['path'], $thumbsSource['path'], $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape);
|
||||
} else {
|
||||
//_error_log("Resize JPG 3 {$jpegSource['path']}, {$thumbsSource['path']}");
|
||||
im_resizeV2($jpegSource['path'], $thumbsSource['path'], $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape);
|
||||
}
|
||||
}
|
||||
// create thumbs
|
||||
if (!file_exists($thumbsSmallSource['path']) && filesize($jpegSource['path']) > 1024) {
|
||||
if (!empty($advancedCustom->useFFMPEGToGenerateThumbs)) {
|
||||
//_error_log("Resize Small JPG 4 useFFMPEGToGenerateThumbs {$jpegSource['path']}, {$thumbsSmallSource['path']}");
|
||||
im_resizeV3($jpegSource['path'], $thumbsSmallSource['path'], $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape);
|
||||
} else {
|
||||
//_error_log("Resize Small JPG 4 {$jpegSource['path']}, {$thumbsSmallSource['path']}");
|
||||
im_resizeV2($jpegSource['path'], $thumbsSmallSource['path'], $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape, 5);
|
||||
}
|
||||
}
|
||||
convertImageIfNotExists($jpegSource['path'], $thumbsSource['path'], $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape, true);
|
||||
convertImageIfNotExists($jpegSource['path'], $thumbsSmallSource['path'], $advancedCustom->thumbsWidthLandscape/2, $advancedCustom->thumbsHeightLandscape/2, true);
|
||||
} else {
|
||||
if ($type == "article") {
|
||||
$obj->poster = "" . getCDN() . "view/img/article.png";
|
||||
|
|
|
@ -34,13 +34,13 @@ class CustomizeAdvanced extends PluginAbstract {
|
|||
return array(
|
||||
'EnableMinifyJS',
|
||||
'usePreloadLowResolutionImages',
|
||||
'useFFMPEGToGenerateThumbs',
|
||||
);
|
||||
}
|
||||
|
||||
public static function getDataObjectExperimental() {
|
||||
return array(
|
||||
'autoPlayAjax',
|
||||
'useFFMPEGToGenerateThumbs',
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,79 +1,80 @@
|
|||
<?php
|
||||
|
||||
global $global, $config;
|
||||
if (!isset($global['systemRootPath'])) {
|
||||
require_once '../../videos/configuration.php';
|
||||
}
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->error = true;
|
||||
|
||||
$live_servers_id = intval($_REQUEST['live_servers_id']);
|
||||
$live_schedule_id = intval($_REQUEST['live_schedule_id']);
|
||||
|
||||
if (!User::isLogged()) {
|
||||
$obj->msg = 'You cant edit this file';
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
$live = AVideoPlugin::loadPluginIfEnabled("Live");
|
||||
|
||||
if (empty($live)) {
|
||||
$obj->msg = 'Plugin not enabled';
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
// A list of permitted file extensions
|
||||
$allowed = ['jpg', 'jpeg', 'gif', 'png'];
|
||||
if (isset($_FILES['file_data']) && $_FILES['file_data']['error'] == 0) {
|
||||
$extension = pathinfo($_FILES['file_data']['name'], PATHINFO_EXTENSION);
|
||||
if (!in_array(strtolower($extension), $allowed)) {
|
||||
$obj->msg = "File extension error [{$_FILES['file_data']['name']}], we allow only (" . implode(",", $allowed) . ")";
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
if (empty($live_schedule_id)) {
|
||||
$obj->file = Live::_getPosterImage(User::getId(), $live_servers_id);
|
||||
$obj->fileThumbs = Live::_getPosterThumbsImage(User::getId(), $live_servers_id);
|
||||
} else {
|
||||
$paths = Live_schedule::getPosterPaths($live_schedule_id);
|
||||
$obj->file = str_replace($global['systemRootPath'], '', $paths['path']);
|
||||
$obj->fileThumbs = str_replace($global['systemRootPath'], '', $paths['path_thumbs']);
|
||||
}
|
||||
|
||||
$tmpDestination = "{$global['systemRootPath']}{$obj->file}.{$extension}";
|
||||
|
||||
make_path($global['systemRootPath'].$obj->file);
|
||||
if (!move_uploaded_file($_FILES['file_data']['tmp_name'], $tmpDestination)) {
|
||||
$obj->msg = "Error on move_file_uploaded_file {$obj->file}" ;
|
||||
die(json_encode($obj));
|
||||
}
|
||||
if (file_exists($tmpDestination)) {
|
||||
convertImage($tmpDestination, $global['systemRootPath'].$obj->file, 70);
|
||||
unlink($tmpDestination);
|
||||
} else {
|
||||
$obj->msg = "Image not moved {$tmpDestination}" ;
|
||||
die(json_encode($obj));
|
||||
}
|
||||
if (file_exists($global['systemRootPath'].$obj->file)) {
|
||||
im_resizeV2($global['systemRootPath'].$obj->file, $global['systemRootPath'].$obj->fileThumbs, $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape);
|
||||
} else {
|
||||
$obj->msg = "Image not created {$tmpDestination} {$global['systemRootPath']}{$obj->file}" ;
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
if (!empty($live_schedule_id)) {
|
||||
$ls = new Live_schedule($live_schedule_id);
|
||||
$array = setLiveKey($ls->getKey(), $ls->getLive_servers_id());
|
||||
$array['users_id'] = $ls->getUsers_id();
|
||||
$array['stats'] = getStatsNotifications(true);
|
||||
Live::notifySocketStats("socketLiveOFFCallback", $array);
|
||||
}
|
||||
|
||||
echo "{}";
|
||||
exit;
|
||||
}
|
||||
$obj->msg = "\$_FILES Error";
|
||||
$obj->FILES = $_FILES;
|
||||
die(json_encode($obj));
|
||||
<?php
|
||||
|
||||
global $global, $config;
|
||||
if (!isset($global['systemRootPath'])) {
|
||||
require_once '../../videos/configuration.php';
|
||||
}
|
||||
|
||||
$obj = new stdClass();
|
||||
$obj->error = true;
|
||||
|
||||
$live_servers_id = intval($_REQUEST['live_servers_id']);
|
||||
$live_schedule_id = intval($_REQUEST['live_schedule_id']);
|
||||
|
||||
if (!User::isLogged()) {
|
||||
$obj->msg = 'You cant edit this file';
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
$live = AVideoPlugin::loadPluginIfEnabled("Live");
|
||||
|
||||
if (empty($live)) {
|
||||
$obj->msg = 'Plugin not enabled';
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
header('Content-Type: application/json');
|
||||
// A list of permitted file extensions
|
||||
$allowed = ['jpg', 'jpeg', 'gif', 'png'];
|
||||
if (isset($_FILES['file_data']) && $_FILES['file_data']['error'] == 0) {
|
||||
$extension = pathinfo($_FILES['file_data']['name'], PATHINFO_EXTENSION);
|
||||
if (!in_array(strtolower($extension), $allowed)) {
|
||||
$obj->msg = "File extension error [{$_FILES['file_data']['name']}], we allow only (" . implode(",", $allowed) . ")";
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
if (empty($live_schedule_id)) {
|
||||
$obj->file = Live::_getPosterImage(User::getId(), $live_servers_id);
|
||||
$obj->fileThumbs = Live::_getPosterThumbsImage(User::getId(), $live_servers_id);
|
||||
} else {
|
||||
$paths = Live_schedule::getPosterPaths($live_schedule_id);
|
||||
$obj->file = str_replace($global['systemRootPath'], '', $paths['path']);
|
||||
$obj->fileThumbs = str_replace($global['systemRootPath'], '', $paths['path_thumbs']);
|
||||
}
|
||||
|
||||
$tmpDestination = "{$global['systemRootPath']}{$obj->file}.{$extension}";
|
||||
|
||||
make_path($global['systemRootPath'].$obj->file);
|
||||
if (!move_uploaded_file($_FILES['file_data']['tmp_name'], $tmpDestination)) {
|
||||
$obj->msg = "Error on move_file_uploaded_file {$obj->file}" ;
|
||||
die(json_encode($obj));
|
||||
}
|
||||
if (file_exists($tmpDestination)) {
|
||||
convertImage($tmpDestination, $global['systemRootPath'].$obj->file, 70);
|
||||
unlink($tmpDestination);
|
||||
} else {
|
||||
$obj->msg = "Image not moved {$tmpDestination}" ;
|
||||
die(json_encode($obj));
|
||||
}
|
||||
if (file_exists($global['systemRootPath'].$obj->file)) {
|
||||
//im_resizeV2($global['systemRootPath'].$obj->file, $global['systemRootPath'].$obj->fileThumbs, $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape);
|
||||
convertImageIfNotExists($global['systemRootPath'].$obj->file, $global['systemRootPath'].$obj->fileThumbs, $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape, true);
|
||||
} else {
|
||||
$obj->msg = "Image not created {$tmpDestination} {$global['systemRootPath']}{$obj->file}" ;
|
||||
die(json_encode($obj));
|
||||
}
|
||||
|
||||
if (!empty($live_schedule_id)) {
|
||||
$ls = new Live_schedule($live_schedule_id);
|
||||
$array = setLiveKey($ls->getKey(), $ls->getLive_servers_id());
|
||||
$array['users_id'] = $ls->getUsers_id();
|
||||
$array['stats'] = getStatsNotifications(true);
|
||||
Live::notifySocketStats("socketLiveOFFCallback", $array);
|
||||
}
|
||||
|
||||
echo "{}";
|
||||
exit;
|
||||
}
|
||||
$obj->msg = "\$_FILES Error";
|
||||
$obj->FILES = $_FILES;
|
||||
die(json_encode($obj));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue