forked from django-ckeditor/django-ckeditor
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#7] Extract core image processing to backends.
- Loading branch information
Showing
11 changed files
with
89 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def create_thumbnail(file_object, format): | ||
raise NotImplementedError | ||
|
||
|
||
def is_image(filepath): | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from io import BytesIO | ||
|
||
from django.core.files.storage import default_storage | ||
|
||
try: | ||
from PIL import Image, ImageOps | ||
except ImportError: | ||
import Image | ||
import ImageOps | ||
|
||
THUMBNAIL_SIZE = (75, 75) | ||
|
||
|
||
def create_thumbnail(file_object, format): | ||
image = Image.open(file_object) | ||
|
||
# Convert to RGB if necessary | ||
# Thanks to Limodou on DjangoSnippets.org | ||
# http://www.djangosnippets.org/snippets/20/ | ||
if image.mode not in ('L', 'RGB'): | ||
image = image.convert('RGB') | ||
|
||
# scale and crop to thumbnail | ||
imagefit = ImageOps.fit(image, THUMBNAIL_SIZE, Image.ANTIALIAS) | ||
thumbnail_io = BytesIO() | ||
imagefit.save(thumbnail_io, format=format) | ||
return thumbnail_io | ||
|
||
|
||
def is_image(filepath): | ||
image = default_storage.open(filepath) | ||
try: | ||
Image.open(image) | ||
except IOError: | ||
return False | ||
else: | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.conf import settings | ||
|
||
|
||
def get_backend(): | ||
backend = getattr(settings, "CKEDITOR_IMAGE_BACKEND", None) | ||
|
||
if backend == "pillow": | ||
from ckeditor.image import pillow_backend as backend | ||
else: | ||
from ckeditor.image import dummy_backend as backend | ||
return backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
django==1.6.0 | ||
Pillow==2.2.1 | ||
selenium==2.38.1 | ||
tox==1.6.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,6 @@ def get_source_files(): | |
'ckeditor', | ||
], | ||
install_requires=[ | ||
'Pillow', | ||
'Django', | ||
], | ||
classifiers=[ | ||
|