Commit graph

72 commits

Author SHA1 Message Date
Matthew Tretter
c3ef5172c3 Rename ImageSpec to ImageSpecField
The ImageSpec class remains for now, but using it throws
deprecation warnings.
2012-02-11 13:06:48 -05:00
Matthew Tretter
343f14ad48 Use old-style string formatting 2012-01-26 18:19:39 -05:00
Timothée Peignier
3bac472561 ImageSpec accepts callable processors arg 2012-01-26 11:01:58 -05:00
Matthew Tretter
dd28557323 Change handling of spec deletion
Though it's not the case with `FileSystemStorage`, attempting to delete
a nonexistent file can cause an exception (as in #80). We want to avoid
these errors but don't want to suppress others raised in the process of
deleting the file, so we first check to see if the file exists.
2011-12-07 00:52:06 -05:00
Matthew Tretter
96878105e9 Indentation tweak 2011-12-02 02:46:27 -05:00
Matthew Tretter
eb425fbae9 Makes evaluation of source_file lazy
This paves the way for future updates that will fix bugs related to
specs not reflecting updates to their source image fields.
2011-12-02 02:28:08 -05:00
Matthew Tretter
ee1fb7f943 Allows None value for processors argument
Fixes #70
2011-11-23 19:34:59 -05:00
Matthew Tretter
62d39ccf9e Gives precedence to user options
Previously, options set by `AutoConvert` had higher precedence than
those explicitly passed by the user. This corrects that.
2011-11-16 10:27:18 -05:00
Matthew Tretter
788365d6db Replaces quality argument with options dict
The `options` argument for `ImageSpec` and `ProcessedImageField`
replaces `quality` and provides a more general solution, allowing the
user access to PIL's format-specific options (including "quality",
"progressive", and "optimize" for JPEGs).
2011-11-16 10:00:35 -05:00
Matthew Tretter
cfa3d01f54 Rename _create() to generate()
After #51 presented a good use case, we decided to make this part of
the API (i.e. remove the underscore). The default value for the `lazy`
kwarg is changed to `True` to reduce the likelihood of accidental
regeneration of images. Closes #54.
2011-11-07 23:07:09 -05:00
Matthew Tretter
8c9a9b8d5c AutoConvert processor
At first, we only had a small amount of code for preserving
transparency in `img_to_fobj`, but as that code grew it became apparent
that it really didn't belong in the utility function. This commit
creates an `AutoConvert` processor which is automatically run before
saving unless you disable it by passing `autoconvert=False` to your
`ImageSpec` or `ProcessedImageField` constructor. `img_to_fobj` is once
again a simple utility function for creating a file object from a PIL
image.
2011-11-06 21:44:31 -05:00
Matthew Tretter
8911836b53 Change how we set ImageFile.MAXBLOCK
Previously, we set it to an arbitrary large number (which turned out
not to be large enough in some cases). Since we may have been
overriding something the user explicitly chose (and our value may be
overridden by another app), that probably wasn't good. After this
change, `MAXBLOCK` is only increased when it needs to be--and even
then, only temporarily.
2011-11-05 21:20:36 -04:00
Matthew Tretter
14bac58373 On-demand loading of PIL plugins 2011-11-02 11:26:24 -04:00
Matthew Tretter
8885325bfc Generated filename is cached 2011-11-01 19:39:54 -04:00
Matthew Tretter
892cce7c7f Fixes extension guessing based on image format
IK relies on PIL's EXTENSION list to map formats to extensions.
However, this list normally isn't populated until an image is loaded.
This change forces the population of the list before examining it.
2011-11-01 18:54:18 -04:00
Bryan Veloso
06c1c678b6 PEP8-ing and whitespacing. 2011-10-31 23:12:03 +09:00
Chris McKenzie
714ff8ae1d adding introspection rule for users with south 2011-10-24 18:18:25 -04:00
Bryan Veloso
6adadafc74 PEP8 and import tweaks. 2011-10-20 12:12:47 +09:00
Bryan Veloso
302399d837 Merge branch 'new_api' of https://github.com/matthewwithanm/django-imagekit into release/1.0.0
* 'new_api' of https://github.com/matthewwithanm/django-imagekit: (63 commits)
  fixing typo
  ImageSpecFile is a proper File
  Typo fix
  A list of ImageSpec names are now stored on the model.
  AdminThumbnailView is now AdminThumbnail
  Docs typo fix
  Adds explicit import of resize module to processors
  fixing bad import in docs
  adding name to AUTHORS
  adding test for new api
  Moved Crop and Fit to resize module.
  More docs edits.
  Typo fix.
  Installation instructions.
  Embracing duck typing.
  Documentation!
  Fix bug
  Bound fields are now cached on the model instance.
  Transpose processor now supports auto EXIF orientation.
  Fix filename formatting.
  ...

Conflicts:
	AUTHORS
	README.rst
	docs/Makefile
	docs/conf.py
	docs/index.rst
	imagekit/__init__.py
	imagekit/defaults.py
	imagekit/management/commands/ikflush.py
	imagekit/models.py
	imagekit/options.py
	imagekit/processors.py
	imagekit/specs.py
	tests/core/tests.py
2011-10-20 12:06:10 +09:00
Matthew Tretter
8147cb85df ImageSpecFile is a proper File
Previously, ImageSpecFile was a file-like object, but didn't actually
extend any of the file classes. Because of this, some of Django's file-
handling code was duplicated. More importantly, instances didn't always
behave as one might expect (if one were familiar with ImageFields),
particularly when the source image was empty. This could have been
especially confusing in templates. (For example, because
ImageSpecFields whose source images didn't exist were still truthy.)
2011-10-10 17:22:06 -04:00
Bryan Veloso
2d4f116e57 Whitespacing and PEP8-ing. 2011-10-11 02:16:22 +09:00
Bryan Veloso
f0269831fd Clearing out some unused imports. 2011-10-11 02:13:31 +09:00
Bryan Veloso
0ddff78068 We no longer import *. 2011-10-11 02:10:38 +09:00
Eric Eldredge
b8e57dccd6 A list of ImageSpec names are now stored on the model.
Previously, ImageSpecFile instances were retrieved (for saving and deleting,
among other possibilities) by iterating over the model instance's attributes.
This change adds ImageSpecFile names to a list (spec_file_names) on an
imagekit meta object on the model (_ik), making later retrieval much cheaper
and more straightforward.
2011-10-06 16:08:14 -04:00
Matthew Tretter
b9aa69e0c0 AdminThumbnailView is now AdminThumbnail
I never liked that the "AdminThumbnailView" was supposed to be defined
on the model, but never looked into it.

This commit puts the definition back where it belongs: in the admin.
Instead of requiring you to add a field (with view logic) to your
model, you now just add a property to your admin class and specify
that property in the `list_display` list.
2011-10-02 21:58:08 -04:00
Matthew Tretter
d6632c95f5 Documentation! 2011-09-25 21:04:11 -04:00
Matthew Tretter
51144daeb6 Fix bug
Eric's fixes in c00ea10b0a meant that
some of the code that already existed to reuse objects would actually
be run for the first time. Naturally, there were some bugs; namely, I
was storing a filename (instead of a File object) in `_file` and a bad
else clause.
2011-09-25 16:18:52 -04:00
Eric Eldredge
c00ea10b0a Bound fields are now cached on the model instance.
ImageSpecFile and AdminThumbnailView are created on the first access, and
then assigned as properties of the model instance for subsequent access.
2011-09-25 12:42:27 -04:00
Eric Eldredge
f570bd0d7f Transpose processor now supports auto EXIF orientation.
Replaced calls to Image.open with an open_image utility function.
The open_image utility calls Image.open, but then wraps the opened Image's
copy method with a version that preserves EXIF data. This allows an
ImageSpec to copy the original image, yet still provide all the original
image's exif data to the processor pipeline.
2011-09-24 23:09:49 -04:00
Matthew Tretter
c694ba644f Fix filename formatting. 2011-09-24 02:04:23 -04:00
Matthew Tretter
6ae4f56ed7 Eliminate repetition in File objects. 2011-09-24 02:04:23 -04:00
Matthew Tretter
f9c4d6b500 Cleanup.
Centralized access of _img, tried to reduce re-calculation of some
properties, renamed _imgfield to source_file to reflect the fact that
it's an ImageFieldFile and not an ImageField.
2011-09-24 02:04:23 -04:00
Matthew Tretter
cc96ba5198 Moved _get_imgfile() into _create()
That was the only place it was being called and it just led to (my)
confusion with the image property.
2011-09-24 02:04:23 -04:00
Eric Eldredge
8a0bc084fe Processors no longer take a file argument.
They only get the image to process now.
2011-09-23 21:25:47 -04:00
Matthew Tretter
7e20b75ced Processors don't care about format.
The process of choosing an image format has been cleaned up and
Processors' role in determining the format has been removed.

Previously, processors would return a tuple containing the modified
image and the format. Other parts of IK overrode PIL's Image.format
with the target format, although that had no effect on PIL and the fact
that it didn't throw an error was just lucky.
2011-09-23 20:18:51 -04:00
Matthew Tretter
15e49be719 Extracted ProcessorPipeline
Pulled some functionality out of _ImageSpecMixin into the ProcessorPipeline
class so it could be used independently of the model-related stuff.
2011-09-23 19:12:04 -04:00
Matthew Tretter
e190e78df5 Rename fields module to models. 2011-09-23 18:06:28 -04:00
Matthew Tretter
fb53981ec8 No need to extend ImageModel.
In fact, ImageModel doesn't exist anymore. Most of IKOptions have also been
removed.
2011-09-21 21:15:09 -04:00
Matthew Tretter
7167016237 Removed specs list from opts. 2011-09-21 20:21:48 -04:00
Matthew Tretter
4e23254e73 Crop processor accepts anchor argument. 2011-09-21 19:02:18 -04:00
Matthew Tretter
b5616d2f75 Move ImageSpec to fields module. 2011-09-21 11:37:29 -04:00
Eric Eldredge
b1c5432310 Implemented post_save and post_delete handlers for ImageSpecs.
Removed the save and clear_cache methods from ImageModel (along with helpers).
Now, whenever an ImageSpec is contributed to a model, handlers are created for
the post_save and post_delete signals. The post_save handler does the work of
running the ImageSpec processors and caching the resulting file, while the
post_delete handler does the work cleaning up the cached files.
2011-09-21 09:56:27 -04:00
Matthew Tretter
80c785f2e5 No need for this. 2011-09-20 21:03:34 -04:00
Matthew Tretter
544d5b874a Added AdminThumbnailView field.
You're no longer restricted to just one, special-case admin thumbnail. Make as
many as you want by adding AdminThumbnailView properties to your model and
including them in your admin class's `list_display` tuple. You can also provide
a custom template. Note that (because this change introduces templates to
imagekit), imagekit is now required in INSTALLED_APPS.

Ideally we could get this stuff out of the model, but we'll have to look into
whether that's possible without making things really complicated.
2011-09-20 19:37:04 -04:00
Matthew Tretter
501d3c7ad3 Now using contribute_to_class.
By creating the Descriptor using contribute_to_class (instead of in
ImageModelBase's __init__), we take the first step towards eliminating the need
to extend ImageModel at all.
2011-09-20 15:44:54 -04:00
Matthew Tretter
57a28091c5 Added default_image_field
This works kind of like Django's models' _default_manager. If your specs don't
specify an image_field, and your IKOptions don't specify a default_image_field,
the first ImageField your model defines will be used.
2011-09-10 00:25:27 -04:00
Matthew Tretter
4c78f2d24c _imgfield is now a property of ImageSpec
Moved _imgfield from ImageModel to ImageSpec. Theoretically, this will allow you
to have specs that use different image fields on the same model.
2011-09-10 00:24:37 -04:00
Matthew Tretter
5e00de5204 Admin thumbnails. 2011-09-10 00:23:47 -04:00
Matthew Tretter
def8dea23f Storage moved onto ImageSpec. 2011-09-08 10:28:54 -04:00
Matthew Tretter
a9895f335a Using spec properties from ImageModel. 2011-09-08 10:00:22 -04:00