Re: Storing images in PostgreSQL databases (again)

From: "Leonel Nunez" <lnunez(at)enelserver(dot)com>
To: "Jean-Christophe Roux" <jcxxr(at)yahoo(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Storing images in PostgreSQL databases (again)
Date: 2006-10-06 00:51:13
Message-ID: 1187.201.155.188.137.1160095873.squirrel@enelserver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Hi,
> If the database had built-in functions to manipulate images (make a
> thumbnail, add text ont it.., make a montage of two pictures) and I could
> write something like
> select thumbnail(image_field, 100, 100) from images_table
> that would be a good reason to go the db route versus the filesystem
> route. A database does more then storing data, it makes convenient to
> play with them. Once my pictures are stored in the database, how do I make
> thumbnails for instance? Maybe the solution already exists; I am curious
> here. Is there a way to integrate ImageMagick into a PostgreSQL workflow?
> By the way, is it practical to set a bytea column (containing pictures) as
> primary key? That would severely slow down many operations I guess.
> JCR
>
>

With Python and the python imaging library you can do this :

image is a bytea field

curs = conn.cursor ()
curs.execute( "select image from images where name = %s" ,(thename, ))
row = curs.fetchone()
if row:
im = Image.open (StringIO.StringIO(row[0]))
im.thumbnail (160,120 )
imagetmp = StringIO.StringIO()
im.save ( imagetmp , "JPEG")
print ("Content-type: image/jpeg\n\n")
print ( imagetmp.getvalue())

with this you get your image to the browser thumbnailed
without touch the filesystem

that's all

Leonel

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Ron Johnson 2006-10-06 01:45:50 Re: Storing images in PostgreSQL databases (again)
Previous Message Joshua D. Drake 2006-10-06 00:42:21 Re: PostgreSQL Database Transfer between machines(again)