Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: jonasundderwolf/django-image-cropping
...
head fork: jonasundderwolf/django-image-cropping
  • 6 commits
  • 5 files changed
  • 0 commit comments
  • 3 contributors
View
3  CONTRIBUTORS
@@ -0,0 +1,3 @@
+Jonas VP <jvp@jonasundderwolf.de>
+Andreas Rieger <andreas.rieger@jonasundderwolf.de>
+Alexander Frenzel <alexander.frenzel@jonasundderwolf.de>
View
5 MANIFEST.in
@@ -1,3 +1,6 @@
+include LICENSE.txt
+include CONTRIBUTORS
+include README.rst
+include MANIFEST.in
recursive-include image_cropping *.py *.txt *.rst * *.css
recursive-include image_cropping/static *.py *.txt *.rst * *.css
-
View
11 README.rst
@@ -22,7 +22,7 @@ Installation
#. Install django-image-cropping using pip. For example::
- pip install -e git+ssh://git@github.com/jonasundderwolf/django-image-cropping.git#egg=django-image-cropping
+ pip install django-image-cropping
#. Add ``easy_thumbnails`` and ``image_cropping`` to your INSTALLED_APPS. ``image_cropping`` is only required if you are using Django 1.3 and ``contrib.staticfiles``
@@ -33,12 +33,11 @@ Installation
'image_cropping.thumbnail_processors.crop_corners',
) + defaults.PROCESSORS
-#. Deploy the necessary static files::
+#. Deploy the necessary static files. If you are using Django 1.3 and ``contrib.staticfiles`` the
+ necessary static files should be picked up automatically. In all other cases you have to copy or
+ symlink the static files. Depending on your setup the command should look similiar to this::
- If you are using Django 1.3 and ``contrib.staticfiles`` the necessary static files should be picked up automatically.
- In all other cases you have to copy or symlink the static files. Depending on your setup the command should look similiar to this::
-
- ln -s ~/.virtualenvs/yourenv/src/django-image-cropping/image_cropping/static/image_cropping/
+ ln -s ~/.virtualenvs/yourenv/src/django-image-cropping/image_cropping/static/image_cropping/
View
66 image_cropping/templatetags/image_cropping.py
@@ -18,3 +18,69 @@ def cropped(context, obj, imagefield, croppingfield):
return thumb.url
+# Sytanx:
+# {% cropped2 instancename ratiofieldname [scale=0.1|width=100|height=200] %}
+@register.tag
+def cropped2(parser, token):
+ args = token.split_contents()
+
+ if len(args) < 3:
+ raise template.TemplateSyntaxError("%r tag requires exactly two arguments" % args[0])
+ if len(args) > 4:
+ raise template.TemplateSyntaxError("%r tag allows only one optional argument" % args[0])
+
+ try:
+ name, value = args[3].split('=')
+ option = (name.lower(), float(value))
+ if not option[0] in ('scale', 'width', 'height'):
+ raise template.TemplateSyntaxError("invalid optional argument %s" % arg[3])
+ if option[1] < 0:
+ raise template.TemplateSyntaxError("%s must have a positive value" % option[0])
+ if option[0] == 'scale' and option[1] > 1:
+ raise template.TemplateSyntaxError("%s must be in range [0:1]" % option[0])
+
+ except ValueError:
+ raise template.TemplateSyntaxError("%s needs an numeric argument" % args[3])
+ except IndexError:
+ option = None
+
+ return CroppingNode(args[1], args[2], option)
+
+class CroppingNode(template.Node):
+ def __init__(self, instance, ratiofieldname, option=None):
+ self.instance = instance
+ self.ratiofieldname = ratiofieldname
+ self.option = option
+
+ def render(self, context):
+ instance = template.Variable(self.instance).resolve(context)
+ ratiofield =instance._meta.get_field(self.ratiofieldname)
+ image = getattr(instance, ratiofield.image_field)
+ size = (int(ratiofield.width), int(ratiofield.height))
+ box = getattr(instance, self.ratiofieldname)
+
+ option = self.option
+ if option:
+ if option[0] == 'scale':
+ width = size[0] * option[1]
+ height = size[1] * option[1]
+ elif option[0] == 'width':
+ width = option[1]
+ height = size[1] * width / size[0]
+ elif option[0] == 'height':
+ height = option[1]
+ width = height * size[0] / size[1]
+ size = (int(width), int(height))
+
+ thumbnailer = get_thumbnailer(image)
+ # TODO force upscaling if requested
+ thumbnail_options = {
+ 'size': size,
+ 'box': box,
+ 'crop': True,
+ 'detail': True,
+ }
+ thumb = thumbnailer.get_thumbnail(thumbnail_options)
+
+ return thumb.url
+
View
20 setup.py
@@ -1,12 +1,13 @@
from distutils.core import setup
from setuptools import setup, find_packages
-setup(name = "image_cropping",
- version = "0.1",
- description = "an app for cropping images",
- author = "JVP",
+setup(name = "django-image-cropping",
+ version = "0.2.2",
+ description = "A reusable app for cropping images easily and non-destructively in Django",
+ long_description=open('README.rst').read(),
+ author = "jonasvp",
author_email = "jvp@jonasundderwolf.de",
- url = "dev.jonasundderwolf.de:image_cropping.git",
+ url = "http://github.com/jonasundderwolf/django-image-cropping",
#Name the folder where your packages live:
#(If you have other packages (dirs) or modules (py files) then
#put them into the package directory - they will be found
@@ -18,4 +19,13 @@
'PIL',
'easy_thumbnails',
],
+ classifiers = [
+ 'Development Status :: 4 - Beta',
+ 'Environment :: Web Environment',
+ 'Framework :: Django',
+ 'Intended Audience :: Developers',
+ 'Operating System :: OS Independent',
+ 'Programming Language :: Python',
+ 'Topic :: Software Development :: Libraries :: Python Modules',
+ ],
)

No commit comments for this range

Something went wrong with that request. Please try again.