forked from Cavemanon/cavepaintings
Added additional media properties to the images table, video, audio, length, and lossless.
Added new event to handle fetching media properties like height, width, and the newly added fields, and admin controls to manually scan files for their properties. Added a search terms content:video and content:audio to search for images that do (or do not) have those flags.
This commit is contained in:
@@ -80,8 +80,8 @@ class TranscodeImage extends Extension
|
||||
|
||||
if ($user->is_admin()) {
|
||||
$engine = $config->get_string(TranscodeConfig::ENGINE);
|
||||
if ($this->can_convert_format($engine, $event->image->ext)) {
|
||||
$options = $this->get_supported_output_formats($engine, $event->image->ext);
|
||||
if ($this->can_convert_format($engine, $event->image->ext, $event->image->lossless)) {
|
||||
$options = $this->get_supported_output_formats($engine, $event->image->ext, $event->image->lossless??false);
|
||||
$event->add_part($this->theme->get_transcode_html($event->image, $options));
|
||||
}
|
||||
}
|
||||
@@ -222,23 +222,27 @@ class TranscodeImage extends Extension
|
||||
}
|
||||
|
||||
|
||||
private function can_convert_format($engine, $format): bool
|
||||
private function can_convert_format($engine, $format, ?bool $lossless = null): bool
|
||||
{
|
||||
return Media::is_input_supported($engine, $format);
|
||||
return Media::is_input_supported($engine, $format, $lossless);
|
||||
}
|
||||
|
||||
|
||||
private function get_supported_output_formats($engine, ?String $omit_format = null): array
|
||||
private function get_supported_output_formats($engine, ?String $omit_format = null, ?bool $lossless = null): array
|
||||
{
|
||||
$omit_format = Media::normalize_format($omit_format);
|
||||
if($omit_format!=null) {
|
||||
$omit_format = Media::normalize_format($omit_format, $lossless);
|
||||
}
|
||||
$output = [];
|
||||
|
||||
|
||||
foreach (self::OUTPUT_FORMATS as $key=>$value) {
|
||||
if ($value=="") {
|
||||
$output[$key] = $value;
|
||||
continue;
|
||||
}
|
||||
if(Media::is_output_supported($engine, $value)
|
||||
&&(empty($omit_format)||$omit_format!=Media::determine_ext($value))) {
|
||||
&&(empty($omit_format)||$omit_format!=$value)) {
|
||||
$output[$key] = $value;
|
||||
}
|
||||
}
|
||||
@@ -278,7 +282,7 @@ class TranscodeImage extends Extension
|
||||
{
|
||||
global $config;
|
||||
|
||||
if ($source_format==Media::determine_ext($target_format)) {
|
||||
if ($source_format==$target_format) {
|
||||
throw new ImageTranscodeException("Source and target formats are the same: ".$source_format);
|
||||
}
|
||||
|
||||
@@ -313,6 +317,7 @@ class TranscodeImage extends Extension
|
||||
try {
|
||||
$result = false;
|
||||
switch ($target_format) {
|
||||
case "webp":
|
||||
case Media::WEBP_LOSSY:
|
||||
$result = imagewebp($image, $tmp_name, $q);
|
||||
break;
|
||||
|
11
ext/transcode/script.js
Normal file
11
ext/transcode/script.js
Normal file
@@ -0,0 +1,11 @@
|
||||
function transcodeSubmit(e) {
|
||||
var format = document.getElementById('transcode_format').value;
|
||||
if(format!="webp-lossless" && format != "png") {
|
||||
var lossless = document.getElementById('image_lossless');
|
||||
if(lossless!=null && lossless.value=='1') {
|
||||
return confirm('You are about to transcode from a lossless format to a lossy format. Lossless formats compress with no quality loss, but converting to a lossy format always results in quality loss, and it will lose more quality every time it is done again on the same image. Are you sure you want to perform this transcode?');
|
||||
} else {
|
||||
return confirm('Converting to a lossy format always results in quality loss, and it will lose more quality every time it is done again on the same image. Are you sure you want to perform this transcode?');
|
||||
}
|
||||
}
|
||||
}
|
@@ -10,8 +10,10 @@ class TranscodeImageTheme extends Themelet
|
||||
global $config;
|
||||
|
||||
$html = "
|
||||
".make_form(make_link("transcode/{$image->id}"), 'POST')."
|
||||
".make_form(make_link("transcode/{$image->id}"), 'POST', false, "",
|
||||
"return transcodeSubmit()")."
|
||||
<input type='hidden' name='image_id' value='{$image->id}'>
|
||||
<input type='hidden' id='image_lossless' name='image_lossless' value='{$image->lossless}'>
|
||||
".$this->get_transcode_picker_html($options)."
|
||||
<br><input id='transcodebutton' type='submit' value='Transcode'>
|
||||
</form>
|
||||
|
Reference in New Issue
Block a user