how to convert Blob to Image?

875 views
Skip to first unread message

Ben Chang

unread,
Jun 20, 2008, 4:52:54 AM6/20/08
to google-a...@googlegroups.com
I can save uploaded pictures into BlobProperty in datastore by those functions:

raw_img = images.Image(pic)
raw_img.resize(width=320, height=240)
raw_img.im_feeling_lucky()

mydb.pic = raw_img.execute_transforms(output_encoding=images.PNG)
mydb.put()



Is there anyway to convert BlobProperty to Image?
Because I want to resize the picture before export to user for reduce  bandwidth.


macarthy

unread,
Jun 20, 2008, 5:01:41 AM6/20/08
to Google App Engine

Ben Chang

unread,
Jun 20, 2008, 6:59:23 AM6/20/08
to google-a...@googlegroups.com
Tks, but I'm not just want to export the Blob data.
 
I hope I can process the Blob data to Image, and resize the image to reduse file size.
 
 
 
Perhaps your meaning is useing: urlfetch.Fetch(picture_url).content ??
 
I'll try this after weekend.
 
 


 
2008/6/20, macarthy <justin.m...@gmail.com>:

Ben Chang

unread,
Jun 20, 2008, 10:44:06 PM6/20/08
to google-a...@googlegroups.com
Yes, it works!!
 
First at all, I have a class "GetPic" to get original image from datastore:
 
class GetPic(webapp.RequestHandler):
    def get(self, pic_id):
        pic = WCPicture.gql("where id = :1", int(pic_id)).get()
        if pic:
            self.response.headers['Content-Type'] = 'image/png'
            self.response.out.write(pic.pic)
 
 
Then I use "urlfetch.Fetch" int another class "GetPic2" to get the data in image type, and I can resize it now:

class GetPic2(webapp.RequestHandler):
    def get(self, pic_id):
        pic = WCPicture.gql("where id = :1", int(pic_id)).get()
        if pic:
            w = self.request.get("w")
            h = self.request.get("h")

            raw_img = images.Image(urlfetch.Fetch("/WebcamCapture/getPic/" + pic_id).content)
            if w<>"" and h<>"":
                raw_img.resize(width=int(w), height=int(h))
            raw_img.im_feeling_lucky()

            self.response.headers['Content-Type'] = 'image/png'
            self.response.out.write(raw_img.execute_transforms(output_encoding=images.PNG))


This might be increase server CPU process, but can hopefully reduce the bandwidth.
 
 
 

 
2008/6/20, Ben Chang <ben.rb...@gmail.com>:

Ross Ridge

unread,
Jun 21, 2008, 12:18:05 AM6/21/08
to Google App Engine
Ben Chang wrote:
> Then I use "urlfetch.Fetch" int another class "GetPic2" to get the data in
> image type, and I can resize it now:

Umm... why not just do it in one request:

class GetPic2(webapp.RequestHandler):
def get(self, pic_id):
pic = WCPicture.gql("where id = :1", int(pic_id)).get()
if pic:
w = self.request.get("w")
h = self.request.get("h")

raw_img = images.Image(pic.pic)
if w!="" and h!="":
raw_img.resize(width=int(w), height=int(h))
raw_img.im_feeling_lucky()

self.response.headers['Content-Type'] = 'image/png'

self.response.out.write(raw_img.execute_transforms(output_encoding=images.PNG))

Ross Ridge

Ben Chang

unread,
Jun 21, 2008, 11:08:33 AM6/21/08
to google-a...@googlegroups.com
Wow... you are right!!
 
Perhaps I did some wrong process which made me failed.
 
Anyway, thank you again.
 


 
2008/6/21, Ross Ridge <rri...@csclub.uwaterloo.ca>:

Sharp-Developer.Net

unread,
Jun 23, 2008, 6:09:54 AM6/23/08
to Google App Engine
Hey Justyin, Ben, do you know by any chance how to upload images/files
to AppEngine using <form method="post" enctype="multipart/form-
data"> ?

I'm trying to use build-in Django 0.96 shipped with Google AppEngine
and got strugled with this :(

Here is a question with details I asked:
http://groups.google.com/group/google-appengine/browse_thread/thread/c0ca9ec08c022c61/157b6b5a9fb5235e#157b6b5a9fb5235e
--
Alexander Trakhimenok
http://sharp-developer.net/

On Jun 20, 10:01 am, macarthy <justin.maccar...@gmail.com> wrote:
> Have a look herehttp://code.google.com/appengine/articles/images.html
> > bandwidth.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages