From: | Jonathan Rogers <jrogers(at)socialserve(dot)com> |
---|---|
To: | psycopg(at)postgresql(dot)org |
Subject: | Re: OT? plpython2u |
Date: | 2016-10-20 18:06:01 |
Message-ID: | 04fdf816-bb06-2cd8-5ea2-269dca900b60@socialserve.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-es-ayuda psycopg |
On 10/20/2016 01:14 PM, Nahum Castro wrote:
> Hello all.
>
> I need to process images on my database, they are stored on a bytea column.
>
> The process consist on scaling and I have done this so far:
>
> CREATE OR REPLACE FUNCTION ajustar(randstring bytea)
> RETURNS bytea AS
> $$
> import PIL
> from PIL import Image
> basewidth = 300
> img = randstring
> wpercent = (basewidth/float(img.size[0]))
> hsize = int((float(img.size[1])*float(wpercent)))
> img = img.resize((basewidth,hsize), PIL.Image.ANTIALIAS)
>
> return img
> $$
> LANGUAGE 'plpython2u' VOLATILE;
As you probably know, Postgres procedural languages are server-side
extensions and therefore have nothing to do with psycopg, which is a
client-side library.
>
> The objective of this pl is read the bytea from the database, scale,
> then replace the scaled image in the database, but I don't know what
> type use to pass to the variable img.
AFAICT, if you pass a bytea value to a plpythonu function, it will
receive a Python str object.
>
> This is the query.
> update personal set foto=ajustar(encode(foto, 'hex')::bytea);
Why are you encoding the binary data into a textual representation? What
image format is stored in column "foto"? Depending on the format, you
probably want to use one of these constructors in function "ajustar":
http://pillow.readthedocs.io/en/3.4.x/reference/Image.html?highlight=Image#PIL.Image.fromstring
http://pillow.readthedocs.io/en/3.4.x/reference/Image.html?highlight=Image#PIL.Image.open
--
Jonathan Rogers
Socialserve.com by Emphasys Software
jrogers(at)emphasys-software(dot)com
--
Jonathan Rogers
Socialserve.com by Emphasys Software
jrogers(at)emphasys-software(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Kernel | 2016-10-20 18:59:35 | Re: Consulta recursiva |
Previous Message | Jonathan Rogers | 2016-10-20 18:03:21 | Re: OT? plpython2u |
From | Date | Subject | |
---|---|---|---|
Next Message | Nahum Castro | 2016-10-20 19:03:39 | Re: OT? plpython2u |
Previous Message | Jonathan Rogers | 2016-10-20 18:03:21 | Re: OT? plpython2u |