1
0
Fork 0
mirror of https://github.com/DanielnetoDotCom/YouPHPTube synced 2025-10-03 01:39:24 +02:00
Daniel Neto 2025-01-18 22:00:34 -03:00
parent 223162fb44
commit 94eb9bac13
4 changed files with 81 additions and 3 deletions

View file

@ -37,6 +37,17 @@ if (isset($_REQUEST['image'])) {
} else {
$path = $images->posterLandscapePath;
}
if(ImagesPlaceHolders::isDefaultImage($path)){
if (empty($_REQUEST['portrait'])) {
$path = $images->posterPortraitPath;
} else {
$path = $images->posterLandscapePath;
}
}
if(ImagesPlaceHolders::isDefaultImage($path)){
$fileName = $video->getFilename();
$path = "{$global['systemRootPath']}videos/{$fileName}/{$fileName}.jpg";
}
$obj->path = $path;
$obj->image = saveCroppieImage($path, "image");
}

View file

@ -0,0 +1,62 @@
<?php
$videos_id = getVideos_id();
?>
<button class="btn btn-primary btn-xs" id="captureScreenshot" data-toggle="tooltip" title="<?php echo __('Thumbnail Select from Time in video'); ?>">
<i class="fa fa-camera"></i> <span class="hidden-md hidden-sm hidden-xs"><?php echo __('Save Frame as Thumbnail'); ?></span>
</button>
<script>
$(document).ready(function () {
$('#captureScreenshot').on('click', async function () {
player.pause();
const video = $('#mainVideo_html5_api')[0]; // Get the video element
if (!video || video.readyState < 2) {
avideoAlertError('The video is not ready to capture a frame.');
return;
}
// Create a canvas element
const canvas = $('<canvas>')[0];
const context = canvas.getContext('2d');
// Set canvas size to match the video resolution
canvas.width = video.videoWidth;
canvas.height = video.videoHeight;
// Draw the current video frame onto the canvas
context.drawImage(video, 0, 0, canvas.width, canvas.height);
// Determine if the image is portrait or not
const isPortrait = canvas.height > canvas.width;
// Convert canvas content to a data URL
const dataURL = canvas.toDataURL('image/png');
// Show confirmation dialog before saving
const imgHtml = `<div style='text-align: center;'>
<img src='${dataURL}' style='max-width: 100%; max-height: 300px; border: 1px solid #ddd;' />
</div>`;
const confirmSave = await avideoConfirm(imgHtml+'Do you want to save this frame as the thumbnail?');
if (!confirmSave) {
return; // Exit if the user cancels
}
// Save the image via AJAX
modal.showPleaseWait();
$.ajax({
url: webSiteRootURL + 'objects/videoEditLight.php',
data: {
videos_id: <?php echo $videos_id; ?>,
image: dataURL.split(',')[1], // Send Base64 data without prefix
portrait: isPortrait ? 1 : 0, // Send portrait flag
},
type: 'post',
success: function (response) {
modal.hidePleaseWait();
avideoResponse(response);
}
});
});
});
</script>

View file

@ -12,12 +12,12 @@ if (defaultIsPortrait()) {
$width = 540;
$height = 800;
$path = $images->posterPortraitPath;
$portreait = 1;
$portrait = 1;
} else {
$width = 1280;
$height = 720;
$path = empty($images->posterLandscapePath) ? ImagesPlaceHolders::getVideoPlaceholder(ImagesPlaceHolders::$RETURN_PATH) : $images->posterLandscapePath;
$portreait = 0;
$portrait = 0;
}
$image = str_replace([$global['systemRootPath'], DIRECTORY_SEPARATOR], [$global['webSiteRootURL'], '/'], $path);
@ -39,7 +39,7 @@ echo $croppie1['html'];
data: {
videos_id: <?php echo $videos_id; ?>,
image: image,
portreait: <?php echo $portreait; ?>,
portrait: <?php echo $portrait; ?>,
},
type: 'post',
success: function (response) {

View file

@ -83,6 +83,11 @@ $description = getSEODescription(emptyHTML($video['description']) ? $video['titl
<button type="button" class="btn btn-primary btn-xs" onclick="avideoModalIframe(webSiteRootURL + 'view/managerVideosLight.php?avideoIframe=1&videos_id=<?php echo $video['id']; ?>');return false;" data-toggle="tooltip" title="<?php echo __("Edit Video"); ?>">
<i class="fa fa-edit"></i> <span class="hidden-md hidden-sm hidden-xs"><?php echo __("Edit Video"); ?></span>
</button>
<?php
if ($video['type'] === Video::$videoTypeVideo) {
require_once $global['systemRootPath'] . 'plugin/PlayerSkins/saveThumbnail.php';
}
?>
<button type="button" class="btn btn-default btn-xs" onclick="avideoModalIframeFull(webSiteRootURL + 'view/videoViewsInfo.php?videos_id=<?php echo $video['id']; ?>');
return false;">
<i class="fa fa-eye"></i> <span class="hidden-md hidden-sm hidden-xs"><?php echo __("Views Info"); ?></span>