Note that there are some explanatory texts on larger screens.

plurals
  1. POUploading, cropping, and saving images in Django using PIL
    primarykey
    data
    text
    <p>I'm trying to upload a profile image in django and crop it on the server side using PIL. I've written a simple function that takes the file and crop areas as parameters, crops the image, and returns it. </p> <p>The problem I'm having is that the returned object does not have a file name and therefore django doesn't know how to save it. Here is the description from the django error page (AttributeError(name) was the error called):</p> <pre><code>/Library/Python/2.6/site-packages/PIL/Image.py in __getattr__ # numpy array interface support new = {} shape, typestr = _conv_type_shape(self) new['shape'] = shape new['typestr'] = typestr new['data'] = self.tostring() return new raise AttributeError(name) ... ## # Returns a string containing pixel data. # # @param encoder_name What encoder to use. The default is to # use the standard "raw" encoder. ▼ Local vars Variable Value self &lt;PIL.Image.Image image mode=RGB size=300x300 at 0x101FCACF8&gt; name '_committed' </code></pre> <p>You can see the image file object does not have a name attached to it like it normally would if uploaded directly from django. I've searched throughout the PIL docs and django docs, but haven't come up with anything that saves a name for the file (e.g., image.save("filename.jpg", "JPEG") didn't work). I'd like to save the file in memory and not have to deal with writing to a disk if possible.</p> <p>I can attach additional code if necessary, but I think/hope I'm just missing something simple with Python. I know there are libraries that will make this easier for me, but right now I'm just trying to understand the fundamentals of image handling with Python/django. Any ideas? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload