But, what if I want to use already uploaded image file, not images
from DB??
This code produces BadImageError:
img_path = os.path.join(os.path.abspath(os.path.dirname
(__file__)), 'img_folder', 'img_file_name')
img_blob = db.Blob(open(img_path).read())
img = images.Image(img_blob)
img.resize(width=80, height=100)
img.im_feeling_lucky()
thumbnail = img.execute_transforms()
Mladen
On Feb 11, 3:34 am, Ian Lewis <[email protected]> wrote:
> Matthew,
>
> I'm using the images api. Up until 1.1.9 my understanding was that importing
> PIL wouldn't work in production (and with 1.1.9 it's enforcing it on the
> dev_server?). Let me pull out the code here,
>
> models.py
>
> class UserProfileImage(db.Model):
> user = db.ReferenceProperty(UserProperties, required=True)
> image = db.BlobProperty(required=True)
> mimetype = db.StringProperty(required=True)
>
> views.py
> ...
> def user_settings(request):
> """
> The user settings page.
> """
> if request.method == 'POST':
> ...
> if not request.user.use_gravatar and 'profile_image' in request.FILES:
> from google.appengine.api import images
> old_profile_image = UserProfileImage.all().filter('user =',
> request.user).get()
>
> uploaded_file = request.FILES['profile_image']
>
> # There should be only one chunk as we can only upload to memory
> image = images.Image(uploaded_file.chunks().next())
> new_width = image.width
> new_height = image.height
> if image.width > 80 or image.height > 80:
> new_width = 80
> new_height = 80
> image.resize(new_width, new_height)
> image_data = image.execute_transforms(output_encoding=images.PNG)
>
> profile_image = UserProfileImage(user=request.user, \
> image=image_data, \
> mimetype='image/png')
> profile_image.put()
>
> if old_profile_image:
> old_profile_image.delete()
> ...
>
> Ian
>
> On Wed, Feb 11, 2009 at 3:52 AM, Matthew Blain
> <[email protected]>wrote:
>
>
>
>
>
> > Hello Ian,
> > How are you accessing PIL? Are you using the Images API* , or are you
> > importing from PIL directly?
>
> > --Matthew
> > *http://code.google.com/appengine/docs/python/images/
>
> > On Feb 10, 5:47 am, Ian Lewis <[email protected]> wrote:
> > > I'm getting an error similar to the errors about not being able to access
> > > skipped files with appengine-django but this time I'm getting an error
> > about
> > > not being able to access the PIL module file Image.py
>
> > > I'm getting a different error pertaining to PIL now. This may or may not
> > be
> > > related to appengine-django.
>
> > > DEBUG 2009-02-10 13:41:24,134 dev_appserver.py] Access to module file
> > > denied: /usr/lib/python2.5/site-packages/PIL/Image.py
>
> > > This causes the dev appserver to hang and use up lots of CPU. I'm using
> > > appengine-django and updated to the latest version in svn.
>
> > > Ian
>
> --
> =======================================
> 株式会社ビープラウド イアン・ルイス
> 〒150-0012
> 東京都渋谷区広尾1-11-2アイオス広尾ビル604
> email: [email protected]
> TEL:03-5795-2707
> FAX:03-5795-2708http://www.beproud.jp/
> =======================================
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---