diff options
author | Andrew Dolgov <[email protected]> | 2021-05-07 18:30:31 +0300 |
---|---|---|
committer | Andrew Dolgov <[email protected]> | 2021-05-07 18:30:31 +0300 |
commit | be061c873e6f63d92c402d35c2d15a39c9bbb127 (patch) | |
tree | ed170972aa97e4bab0581a6c13836985531c63fa | |
parent | ffebb5f2c7ca4f45261c20d317ad0d90a07c547a (diff) |
add configurable quality setting
-rw-r--r-- | init.php | 38 |
1 files changed, 25 insertions, 13 deletions
@@ -2,6 +2,7 @@ class Api_Resize_Media extends Plugin { const MAX_WIDTH = 1024; + const DEFAULT_QUALITY = 80; /* @var PluginHost $host */ private $host; @@ -35,7 +36,7 @@ class Api_Resize_Media extends Plugin { } private function make_thumbnail($input_filename, $output_filename, $dim_max_x = 600, $dim_max_y = 600, - $content_type = "", $force_stamp = false) { + $content_type = "", $force_stamp = false, $quality = self::DEFAULT_QUALITY) { if ($content_type == "image/webp") { $o_im = @imagecreatefromwebp($input_filename); @@ -100,7 +101,7 @@ class Api_Resize_Media extends Plugin { else @imagePng($t_im, $output_filename, 5);*/ - imagewebp($t_im, $output_filename, 80); + imagewebp($t_im, $output_filename, $quality); imageDestroy($o_im); imageDestroy($t_im); @@ -122,8 +123,8 @@ class Api_Resize_Media extends Plugin { return; } - if ($width > Api_Resize_Media::MAX_WIDTH) - $width = Api_Resize_Media::MAX_WIDTH; + if ($width > self::MAX_WIDTH) + $width = self::MAX_WIDTH; if ($this->cache->exists($local_filename)) { @@ -310,7 +311,7 @@ class Api_Resize_Media extends Plugin { } function hook_enclosure_entry($enc) { - $force_width = (int) $this->host->get($this, "force_width", 0); + $force_width = (int) $this->host->profile_get($this, "force_width", 0); $enc["content_url"] = $this->rewrite_url_if_needed($enc["content_url"], $force_width); @@ -318,13 +319,13 @@ class Api_Resize_Media extends Plugin { } function hook_render_article_cdm($row) { - $force_width = (int) $this->host->get($this, "force_width", 0); + $force_width = (int) $this->host->profile_get($this, "force_width", 0); return $this->process_article(["article" => $row], $force_width); } function hook_render_article($row) { - $force_width = (int) $this->host->get($this, "force_width", 0); + $force_width = (int) $this->host->profile_get($this, "force_width", 0); return $this->process_article(["article" => $row], $force_width); } @@ -369,7 +370,8 @@ class Api_Resize_Media extends Plugin { function hook_prefs_tab($args) { if ($args != "prefFeeds") return; - $force_width = (int) $this->host->get($this, "force_width", 0); + $force_width = (int) $this->host->profile_get($this, "force_width", 0); + $quality = (int) $this->host->profile_get($this, "force_width", self::DEFAULT_QUALITY); ?> <div dojoType='dijit.layout.AccordionPane' @@ -388,10 +390,18 @@ class Api_Resize_Media extends Plugin { } </script> - <fieldset> - <label><?= $this->__( "Also resize in web UI (width, 0 - disables)") ?></label> + <fieldset class='prefs'> + <label><?= $this->__( "Also resize in web UI (width, 0 - disables):") ?></label> <input dojoType='dijit.form.NumberSpinner' - required='1' name='force_width' id='api_resize_force_width' value="<?= $force_width ?>"> <?= $this->__('pixels') ?> + required='1' name='force_width' value="<?= $force_width ?>"> + + <?= $this->__('pixels') ?> + </fieldset> + + <fieldset class='prefs'> + <label><?= $this->__( "Output WEBP quality:") ?></label> + <input dojoType='dijit.form.NumberSpinner' min='1' constraints='{min:1,max:100,places:0}' + required='1' name='quality' value="<?= $quality ?>"> </fieldset> <hr/> @@ -405,10 +415,12 @@ class Api_Resize_Media extends Plugin { function save() { $force_width = (int) $_POST["force_width"]; + $quality = (int) $_POST["quality"]; - $this->host->set($this, "force_width", $force_width); + $this->host->profile_set($this, "force_width", $force_width); + $this->host->profile_set($this, "quality", $quality); - echo $this->T_sprintf("Data saved (%d)", $force_width); + echo $this->T_sprintf("Data saved (%d, %d)", $force_width, $quality); } function api_version() { |