1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 09:49:28 +02:00

Make better portrait thumbnails

This commit is contained in:
DanieL 2022-12-26 14:58:57 -03:00
parent 57f923936a
commit 2ab1c49bb0
4 changed files with 95 additions and 121 deletions

View file

@ -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) { 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"); //_error_log("im_resizeV2: $file_src, $file_dest, $wd, $hd, $q");
$newImage = im_resize($file_src, $file_dest, $wd, $hd, 100); $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); $old_y = imageSY($src_img);
$sizes = scaleUpAndMantainAspectRatioFinalSizes($wd, $old_x, $hd, $old_y); $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_w = $sizes['w'];
$thumb_h = $sizes['h']; $thumb_h = $sizes['h'];
@ -3899,7 +3906,7 @@ function convertImageIfNotExists($source, $destination, $width, $height, $scaleU
_error_log("convertImageToRoku: source does not exists"); _error_log("convertImageToRoku: source does not exists");
return false; return false;
} }
if (file_exists($destination)) { if (file_exists($destination) && filesize($destination) > 1024) {
$sizes = getimagesize($destination); $sizes = getimagesize($destination);
if ($sizes[0] < $width || $sizes[1] < $height) { if ($sizes[0] < $width || $sizes[1] < $height) {
_error_log("convertImageIfNotExists: file is smaller " . json_encode($sizes)); _error_log("convertImageIfNotExists: file is smaller " . json_encode($sizes));

View file

@ -4179,24 +4179,8 @@ if (!class_exists('Video')) {
$obj->thumbsGif = $gifSource['url']; $obj->thumbsGif = $gifSource['url'];
} }
if (file_exists($jpegPortraitSource['path'])) { if (file_exists($jpegPortraitSource['path'])) {
// create thumbs convertImageIfNotExists($jpegPortraitSource['path'], $jpegPortraitThumbs['path'], $advancedCustom->thumbsWidthPortrait, $advancedCustom->thumbsHeightPortrait, true);
if (!file_exists($jpegPortraitThumbs['path']) && filesize($jpegPortraitSource['path']) > 1024) { convertImageIfNotExists($jpegPortraitThumbsSmall['path'], $jpegPortraitThumbsSmall['path'], $advancedCustom->thumbsWidthPortrait/2, $advancedCustom->thumbsHeightPortrait/2, true);
_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);
}
}
} else { } else {
if ($type == "article") { if ($type == "article") {
$obj->posterPortrait = "" . getCDN() . "view/img/article_portrait.png"; $obj->posterPortrait = "" . getCDN() . "view/img/article_portrait.png";
@ -4229,26 +4213,8 @@ if (!class_exists('Video')) {
if (file_exists($jpegSource['path'])) { if (file_exists($jpegSource['path'])) {
$obj->poster = $jpegSource['url']; $obj->poster = $jpegSource['url'];
$obj->thumbsJpg = $thumbsSource['url']; $obj->thumbsJpg = $thumbsSource['url'];
// create thumbs convertImageIfNotExists($jpegSource['path'], $thumbsSource['path'], $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape, true);
if (!file_exists($thumbsSource['path']) && filesize($jpegSource['path']) > 1024) { convertImageIfNotExists($jpegSource['path'], $thumbsSmallSource['path'], $advancedCustom->thumbsWidthLandscape/2, $advancedCustom->thumbsHeightLandscape/2, true);
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);
}
}
} else { } else {
if ($type == "article") { if ($type == "article") {
$obj->poster = "" . getCDN() . "view/img/article.png"; $obj->poster = "" . getCDN() . "view/img/article.png";

View file

@ -34,13 +34,13 @@ class CustomizeAdvanced extends PluginAbstract {
return array( return array(
'EnableMinifyJS', 'EnableMinifyJS',
'usePreloadLowResolutionImages', 'usePreloadLowResolutionImages',
'useFFMPEGToGenerateThumbs',
); );
} }
public static function getDataObjectExperimental() { public static function getDataObjectExperimental() {
return array( return array(
'autoPlayAjax', 'autoPlayAjax',
'useFFMPEGToGenerateThumbs',
); );
} }

View file

@ -57,7 +57,8 @@ if (isset($_FILES['file_data']) && $_FILES['file_data']['error'] == 0) {
die(json_encode($obj)); die(json_encode($obj));
} }
if (file_exists($global['systemRootPath'].$obj->file)) { if (file_exists($global['systemRootPath'].$obj->file)) {
im_resizeV2($global['systemRootPath'].$obj->file, $global['systemRootPath'].$obj->fileThumbs, $advancedCustom->thumbsWidthLandscape, $advancedCustom->thumbsHeightLandscape); //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 { } else {
$obj->msg = "Image not created {$tmpDestination} {$global['systemRootPath']}{$obj->file}" ; $obj->msg = "Image not created {$tmpDestination} {$global['systemRootPath']}{$obj->file}" ;
die(json_encode($obj)); die(json_encode($obj));