Re: OT? plpython2u

Поиск
Список
Период
Сортировка
От Nahum Castro
Тема Re: OT? plpython2u
Дата
Msg-id CABqArLgGUPscXXcoKyNaLYmiiJMCm+Jivzvjkd2i1fCF0wx4Pw@mail.gmail.com
обсуждение исходный текст
Ответ на Re: OT? plpython2u  (Jonathan Rogers <jrogers@socialserve.com>)
Ответы Re: OT? plpython2u  (Adrian Klaver <adrian.klaver@aklaver.com>)
Список psycopg


2016-10-20 13:06 GMT-05:00 Jonathan Rogers <jrogers@socialserve.com>:
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.
​Thanks, but rather than help in plpython is how to pass the variable bytea from postgres to an image in python.

>
> 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.

​That is where i get confused, what is stored in the db is in bytea, how I do to transform in a str?​

 

>
> 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":

​Sorry I forgot, all images are in jpeg​ format.
 

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

​Again thanks.​
Nahum


--
Jonathan Rogers
Socialserve.com by Emphasys Software
jrogers@emphasys-software.com

--
Jonathan Rogers
Socialserve.com by Emphasys Software
jrogers@emphasys-software.com


--
Sent via psycopg mailing list (psycopg@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/psycopg



--
Nahum Castro González
Blvd. Perdigón 214, Brisas del Lago.
CP 37207
León, Guanajuato, México
Tel (477)1950304
Cel (477)1274694

В списке psycopg по дате отправления:

Предыдущее
От: Jonathan Rogers
Дата:
Сообщение: Re: OT? plpython2u
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: OT? plpython2u