From be061c873e6f63d92c402d35c2d15a39c9bbb127 Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Fri, 7 May 2021 18:30:31 +0300 Subject: add configurable quality setting --- init.php | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/init.php b/init.php index 3dd171a..c5c1168 100644 --- a/init.php +++ b/init.php @@ -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); ?>
-
- +
+ __('pixels') ?> + required='1' name='force_width' value=""> +   + __('pixels') ?> +
+ +
+ +

@@ -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() { -- cgit v1.2.3