Gilles has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/251427

Change subject: Thumbor filter to sharpen conditionally
......................................................................

Thumbor filter to sharpen conditionally

Bug: T112545
Change-Id: I49ec108d11a2bfd544e454e073f872f52b9148c1
---
A LICENSE
A conditionalsharpen.py
A requirements.txt
A tox.ini
4 files changed, 85 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/thumbor/conditional-sharpen 
refs/changes/27/251427/1

diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..ca88538
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,22 @@
+The MIT License (MIT)
+
+Copyright (c) 2015 Gilles Dubuc
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+
diff --git a/conditionalsharpen.py b/conditionalsharpen.py
new file mode 100755
index 0000000..2af64b8
--- /dev/null
+++ b/conditionalsharpen.py
@@ -0,0 +1,50 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+# thumbor imaging service
+# https://github.com/thumbor/thumbor/wiki
+
+# Licensed under the MIT license:
+# http://www.opensource.org/licenses/mit-license
+# Copyright (c) 2011 globo.com [email protected]
+
+# This is a fork of the thumbor.filters.sharpen filter
+# This version only applies the sharpening if the thumbnail resize
+# ratio is smaller than the resize ratio threshold passed as the
+# last parameter
+
+from thumbor.filters import BaseFilter, filter_method
+from thumbor.ext.filters import _sharpen
+
+
+class Filter(BaseFilter):
+
+    @filter_method(
+        BaseFilter.DecimalNumber,
+        BaseFilter.DecimalNumber,
+        BaseFilter.Boolean,
+        BaseFilter.DecimalNumbe
+    )
+    def conditionalsharpen(
+            self,
+            amount,
+            radius,
+            luminance_only,
+            resize_ratio_threshold):
+
+        width, height = self.engine.size
+        original_width = self.engine.source_width
+        original_height = self.engine.source_height
+        mode, data = self.engine.image_data_as_rgb()
+        source_sum = float(original_width + original_height)
+        destination_sum = float(width + height)
+        resize_ratio = destination_sum / source_sum
+
+        if resize_ratio < resize_ratio_threshold:
+            imgdata = _sharpen.apply(
+                mode, width, height, amount, radius,
+                luminance_only, data
+            )
+            self.engine.set_image_data(imgdata)
+        else:
+            self.engine.set_image_data(data)
diff --git a/requirements.txt b/requirements.txt
new file mode 100644
index 0000000..ef29d7d
--- /dev/null
+++ b/requirements.txt
@@ -0,0 +1 @@
+thumbor
diff --git a/tox.ini b/tox.ini
new file mode 100644
index 0000000..9e359d2
--- /dev/null
+++ b/tox.ini
@@ -0,0 +1,12 @@
+[tox]
+minversion = 1.6
+skipsdist = True
+envlist = flake8
+
+[testenv]
+setenv = VIRTUAL_ENV={envdir}
+deps = -r{toxinidir}/requirements.txt
+
+[testenv:flake8]
+commands = flake8 {posargs}
+deps = flake8

-- 
To view, visit https://gerrit.wikimedia.org/r/251427
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I49ec108d11a2bfd544e454e073f872f52b9148c1
Gerrit-PatchSet: 1
Gerrit-Project: thumbor/conditional-sharpen
Gerrit-Branch: master
Gerrit-Owner: Gilles <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to