Skip to content

Commit

Permalink
No Upscale filter
Browse files Browse the repository at this point in the history
  • Loading branch information
heynemann committed Aug 13, 2014
1 parent 95b0c0d commit 0cdcfda
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,5 @@ opencv
/debian/thumbor.prerm.debhelper
/debian/thumbor.substvars
/debian/tmp/
.ropeproject/
.venv
1 change: 1 addition & 0 deletions thumbor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@
'thumbor.filters.convolution',
'thumbor.filters.blur',
'thumbor.filters.extract_focal',
'thumbor.filters.no_upscale',
],
'List of filters that thumbor will allow to be used in generated images. All of them must be ' +
'full names of python modules (python must be able to import it)', 'Filters')
Expand Down
1 change: 1 addition & 0 deletions thumbor/filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
STRIP_QUOTE = re.compile(r"^'(.+)'$")
PHASE_POST_TRANSFORM = 'post_transform'
PHASE_PRE_LOAD = 'pre-load'
PHASE_AFTER_LOAD = 'after-load'


def filter_method(*args, **kwargs):
Expand Down
25 changes: 25 additions & 0 deletions thumbor/filters/no_upscale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# thumbor imaging service
# https://github.com/globocom/thumbor/wiki

# Licensed under the MIT license:
# http://www.opensource.org/licenses/mit-license
# Copyright (c) 2011 globo.com timehome@corp.globo.com


import thumbor.filters
from thumbor.filters import BaseFilter, filter_method


class Filter(BaseFilter):
phase = thumbor.filters.PHASE_AFTER_LOAD

@filter_method()
def no_upscale(self):
image_size = self.engine.size
if self.context.request.width > image_size[0]:
self.context.request.width = image_size[0]
if self.context.request.height > image_size[1]:
self.context.request.height = image_size[1]
13 changes: 8 additions & 5 deletions thumbor/handlers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ def callback(normalized, buffer=None, engine=None):
engine = self.context.request.engine
engine.load(buffer, req.extension)

self.normalize_crops(normalized, req, engine)
def transform():
self.normalize_crops(normalized, req, engine)

if req.meta:
self.context.request.engine = JSONEngine(engine, req.image_url, req.meta_callback)
if req.meta:
self.context.request.engine = JSONEngine(engine, req.image_url, req.meta_callback)

after_transform_cb = functools.partial(self.after_transform, self.context)
Transformer(self.context).transform(after_transform_cb)
after_transform_cb = functools.partial(self.after_transform, self.context)
Transformer(self.context).transform(after_transform_cb)

self.filters_runner.apply_filters(thumbor.filters.PHASE_AFTER_LOAD, transform)

self._fetch(self.context.request.image_url, self.context.request.extension, callback)

Expand Down
1 change: 1 addition & 0 deletions thumbor/thumbor.conf
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ ALLOW_UNSAFE_URL = True
#'thumbor.filters.rotate',
#'thumbor.filters.format',
#'thumbor.filters.max_bytes',
#'thumbor.filters.no_upscale',

## can only be applied if there are already points for the image being served
## this means that either you are using the local face detector or the image
Expand Down

0 comments on commit 0cdcfda

Please sign in to comment.