Is 'img_folder' a static file? If so, you can't access it directly
using 'open'.

"For efficiency, App Engine stores and serves static files separately
from application files. Static files are not available in the
application's file system. If you have data files that need to be read
by the application code, the data files must be application files, and
must not be matched by a static file pattern."

http://code.google.com/appengine/docs/python/tools/configuration.html#Static_File_Handlers

If it's not a static file, then it should work, though I'm not sure
(not having personally used it) what the db.Blob conversion will do
there--probably nothing. An example of using the images api with
uploaded data can be found in the images-demo example:

http://code.google.com/p/google-app-engine-samples/source/browse/trunk/images-demo/images_demo.py#159

http://images-demo.appspot.com/

--Matthew

On Feb 23, 6:13 am, Mladen Stanojevic <smla...@gmail.com> wrote:
> 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 <ianmle...@gmail.com> 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 
> > <matthew.bl...@google.com>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 <ianmle...@gmail.com> 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: ianmle...@beproud.jp
> > 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 google-appengine@googlegroups.com
To unsubscribe from this group, send email to 
google-appengine+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to