Skip to content

Commit 6225b5b

Browse files
committed
First commit
1 parent 286cecb commit 6225b5b

15 files changed

Lines changed: 648 additions & 1 deletion

.coveragerc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[run]
2+
omit =
3+
*tests.py
4+
branch = True
5+
source =
6+
graphicsmagick_engine
7+
8+
[report]
9+
exclude_lines =
10+
pragma: no cover
11+
def __repr__
12+
raise NotImplementedError
13+
if __name__ == .__main__.:
14+
from urllib.parse import parse_qs
15+
except ImportError:

.travis.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
language: python
2+
python:
3+
- "2.7"
4+
5+
install:
6+
#removing unwanted packages
7+
- sudo apt-get remove --purge -y $(< unwanted_packages)
8+
# update aptitude
9+
- sudo apt-get update -y
10+
- sudo apt-get install aptitude -y
11+
12+
# install aptitude packages
13+
- LDFLAGS=-lm sudo aptitude install -y $(< requirements)
14+
15+
- sudo apt-get autoremove -y
16+
17+
- df -h
18+
19+
# weird travis-ci python paths
20+
- export PYTHONPATH=$PYTHONPATH:/usr/lib/pymodules/python2.7/
21+
- export PYTHONPATH=$PYTHONPATH:/usr/lib/python2.7/dist-packages
22+
- export PYTHONPATH=$PYTHONPATH:/usr/lib/pyshared/python2.7/
23+
- export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages/
24+
25+
# verify both requirements were met
26+
- INSTALLDIR=$(python -c "import os; import numpy; print(os.path.dirname(numpy.__file__))")
27+
28+
# Fix distribute
29+
- wget http://python-distribute.org/distribute_setup.py
30+
- python distribute_setup.py
31+
32+
# install python requirements
33+
- make setup
34+
35+
script:
36+
# finally run tests
37+
- make test

Makefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
test: unit integration
2+
3+
unit:
4+
@coverage run --branch `which nosetests` -vv --with-yanc -s tests/unit/
5+
@coverage report -m
6+
7+
coverage-html: unit
8+
@coverage html -d cover
9+
10+
integration:
11+
@`which nosetests` -vv --with-yanc -s tests/integration/
12+
13+
setup:
14+
@pip install -U -e .\[tests\]
15+
16+
run:
17+
@thumbor -c thumbor.conf -l debug

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,40 @@
11
opencv-engine
22
=============
33

4-
Thumbor engine for the openCV imaging library.
4+
Thumbor engine for the OpenCV imaging library.
5+
6+
This engine used to be built-in in thumbor, but from now on this is where it will be maintained. For more informations on development check the contributing section.
7+
8+
Installing
9+
==========
10+
11+
Just pip install it:
12+
13+
$ pip install opencv-engine
14+
15+
In order to use this engine with your thumbor install, specify this engine as the imaging engine:
16+
17+
# imaging engine to use to process images
18+
ENGINE = 'opencv_engine'
19+
20+
Instead of the value you used before of 'thumbor.engines.opencv'.
21+
22+
Contributing
23+
============
24+
25+
Fork, commit, pull request. Rinse and repeat.
26+
27+
License
28+
=======
29+
30+
OpenCV-Engine is licensed under the MIT License:
31+
32+
The MIT License
33+
34+
Copyright (c) 2014 Globo.com timehome@corp.globo.com.com
35+
36+
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:
37+
38+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
39+
40+
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.

opencv_engine/__init__.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
import logging
5+
6+
__version__ = '0.1.0'
7+
8+
try:
9+
from opencv_engine.engine import Engine # NOQA
10+
except ImportError:
11+
logging.warning('Could not import opencv_engine. Probably due to setup.py installing it.')

opencv_engine/engine.py

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
# thumbor imaging service - opencv engine
5+
# https://github.com/thumbor/opencv-engine
6+
7+
# Licensed under the MIT license:
8+
# http://www.opensource.org/licenses/mit-license
9+
# Copyright (c) 2014 globo.com timehome@corp.globo.com
10+
11+
import cv
12+
13+
from thumbor.engines import BaseEngine
14+
15+
FORMATS = {
16+
'.jpg': 'JPEG',
17+
'.jpeg': 'JPEG',
18+
'.gif': 'GIF',
19+
'.png': 'PNG'
20+
}
21+
22+
23+
class Engine(BaseEngine):
24+
25+
def create_image(self, buffer):
26+
# FIXME: opencv doesn't support gifs, even worse, the library
27+
# segfaults when trying to decoding a gif. An exception is a
28+
# less drastic measure.
29+
try:
30+
if FORMATS[self.extension] == 'GIF':
31+
raise ValueError("opencv doesn't support gifs")
32+
except KeyError:
33+
pass
34+
35+
imagefiledata = cv.CreateMatHeader(1, len(buffer), cv.CV_8UC1)
36+
cv.SetData(imagefiledata, buffer, len(buffer))
37+
img0 = cv.DecodeImage(imagefiledata, cv.CV_LOAD_IMAGE_COLOR)
38+
39+
return img0
40+
41+
@property
42+
def size(self):
43+
return cv.GetSize(self.image)
44+
45+
def normalize(self):
46+
pass
47+
48+
def resize(self, width, height):
49+
thumbnail = cv.CreateMat(int(round(height, 0)), int(round(width, 0)), cv.CV_8UC3)
50+
cv.Resize(self.image, thumbnail, cv.CV_INTER_AREA)
51+
self.image = thumbnail
52+
53+
def crop(self, left, top, right, bottom):
54+
new_width = right - left
55+
new_height = bottom - top
56+
cropped = cv.CreateImage((new_width, new_height), 8, 3)
57+
src_region = cv.GetSubRect(self.image, (left, top, new_width, new_height))
58+
cv.Copy(src_region, cropped)
59+
60+
self.image = cropped
61+
62+
def flip_vertically(self):
63+
cv.Flip(self.image, None, 1)
64+
65+
def flip_horizontally(self):
66+
cv.Flip(self.image, None, 0)
67+
68+
def read(self, extension=None, quality=None):
69+
if quality is None:
70+
quality = self.context.config.QUALITY
71+
72+
options = None
73+
extension = extension or self.extension
74+
try:
75+
if FORMATS[extension] == 'JPEG':
76+
options = [cv.CV_IMWRITE_JPEG_QUALITY, quality]
77+
except KeyError:
78+
#default is JPEG so
79+
options = [cv.CV_IMWRITE_JPEG_QUALITY, quality]
80+
81+
return cv.EncodeImage(extension, self.image, options or []).tostring()
82+
83+
def get_image_data(self):
84+
return self.image.tostring()
85+
86+
def set_image_data(self, data):
87+
cv.SetData(self.image, data)
88+
89+
def convert_to_rgb(self):
90+
return self.get_image_mode(), self.get_image_data()
91+
92+
def get_image_mode(self):
93+
# TODO: Handle pngs with alpha channel
94+
return 'BGR'
95+
96+
def draw_rectangle(self, x, y, width, height):
97+
cv.Rectangle(self.image, (int(x), int(y)), (int(x + width), int(y + height)), cv.Scalar(255, 255, 255, 1.0))
98+
99+
def convert_to_grayscale(self):
100+
grayscaled = cv.CreateImage((self.image.width, self.image.height), self.image.depth, 1) # one single channel
101+
cv.CvtColor(self.image, grayscaled, cv.CV_RGB2GRAY)
102+
self.image = grayscaled

requirements

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
libevent-dev
2+
libxml2-dev
3+
libcurl4-gnutls-dev
4+
python-pycurl-dbg
5+
librtmp-dev
6+
libatlas-base-dev
7+
gfortran
8+
liblapack-dev
9+
libblas-dev
10+
build-essential
11+
checkinstall
12+
git
13+
pkg-config
14+
cmake
15+
libpng12-0
16+
libpng12-dev
17+
libpng++-dev
18+
libpng3
19+
libpnglite-dev
20+
libpngwriter-dev
21+
libpngwriter
22+
libfaac-dev
23+
libjack-jackd2-dev
24+
libjasper-dev
25+
libjasper-runtime
26+
libjasper1
27+
libmp3lame-dev
28+
libopencore-amrnb-dev
29+
libopencore-amrwb-dev
30+
libsdl1.2-dev
31+
libtheora-dev
32+
libva-dev
33+
libvdpau-dev
34+
libvorbis-dev
35+
libx11-dev
36+
libxfixes-dev
37+
libxvidcore-dev
38+
texi2html
39+
yasm
40+
zlib1g-dev
41+
zlib1g-dbg
42+
zlib1g
43+
libgstreamer0.10-0
44+
libgstreamer0.10-dev
45+
libgstreamer0.10-0-dbg
46+
gstreamer0.10-tools
47+
gstreamer0.10-plugins-base
48+
libgstreamer-plugins-base0.10-dev
49+
gstreamer0.10-plugins-good
50+
gstreamer0.10-plugins-ugly
51+
gstreamer0.10-plugins-bad
52+
gstreamer0.10-ffmpeg
53+
pngtools
54+
libtiff4-dev
55+
libtiff4
56+
libtiffxx0c2
57+
libtiff-tools
58+
libjpeg8
59+
libjpeg8-dev
60+
libjpeg8-dbg
61+
libjpeg-progs
62+
libavcodec-dev
63+
libavcodec53
64+
libavformat53
65+
libavformat-dev
66+
libxine1-ffmpeg
67+
libxine-dev
68+
libxine1-bin
69+
libunicap2
70+
libunicap2-dev
71+
libdc1394-22-dev
72+
libdc1394-22
73+
libdc1394-utils
74+
swig
75+
libpython2.7
76+
python-dev
77+
python2.7-dev
78+
libjpeg-progs
79+
libjpeg-dev
80+
libgtk2.0-0
81+
libgtk2.0-dev
82+
gtk2-engines-pixbuf
83+
python-numpy
84+
python-opencv
85+
redis-server
86+
libgraphicsmagick++1-dev
87+
libgraphicsmagick++3
88+
libboost-python-dev
89+
tree
90+
webp
91+
libwebp-dev

setup.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
4+
from setuptools import setup, find_packages
5+
from opencv_engine import __version__
6+
7+
tests_require = [
8+
'mock',
9+
'nose',
10+
'coverage',
11+
'yanc',
12+
'colorama',
13+
'preggy',
14+
'ipdb',
15+
'coveralls',
16+
'numpy',
17+
]
18+
19+
setup(
20+
name='opencv_engine',
21+
version=__version__,
22+
description='OpenCV imaging engine for thumbor.',
23+
long_description='''
24+
OpenCV imaging engine for thumbor.
25+
''',
26+
keywords='thumbor imaging opencv',
27+
author='Globo.com',
28+
author_email='timehome@corp.globo.com',
29+
url='',
30+
license='MIT',
31+
classifiers=[
32+
'Development Status :: 4 - Beta',
33+
'Intended Audience :: Developers',
34+
'License :: OSI Approved :: MIT License',
35+
'Natural Language :: English',
36+
'Operating System :: MacOS',
37+
'Operating System :: POSIX',
38+
'Operating System :: Unix',
39+
'Operating System :: OS Independent',
40+
'Programming Language :: Python :: 2.7',
41+
],
42+
packages=find_packages(),
43+
include_package_data=True,
44+
install_requires=[
45+
'thumbor',
46+
],
47+
extras_require={
48+
'tests': tests_require,
49+
}
50+
)

tests/__init__.py

Whitespace-only changes.

tests/integration/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)