Unix Technical Forum

Resizing images contained in oid fields

This is a discussion on Resizing images contained in oid fields within the pgsql Admins forums, part of the PostgreSQL category; --> Hello, I have a table where an oid field is used for saving images. I'm thinking about getting a ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Admins

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-10-2008, 01:34 AM
juanmime@ono.com
 
Posts: n/a
Default Resizing images contained in oid fields

Hello,

I have a table where an oid field is used for saving images. I'm thinking
about getting a little snapshot of all images without downloading the full
images. I only want to download some entire images. I'm thinking in something
like this:

create table images (
id serial primary key,
title varchar not null,
photo_id oid
);


select title, snapshot(photo_oid, 120, 120) as snap from images

In this case, the snapshot function returns the resized snapshot of the original
image.

I think that the core of function could be similar to this:
1) Obtain the image
2) Resize the Image to new size
3) Return the Resized Image

Do you know if there exists a function like this ("snapshot")?
Otherwise, What is the type returned by the function ? What suitable procedure
language should I use ? What image library for the redimension ?

Thanks you very much.



---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-10-2008, 01:35 AM
Michael Fuhr
 
Posts: n/a
Default Re: Resizing images contained in oid fields

On Mon, Mar 21, 2005 at 05:12:52PM +0100, juanmime@ono.com wrote:
>
> I have a table where an oid field is used for saving images. I'm thinking
> about getting a little snapshot of all images without downloading the full
> images. I only want to download some entire images. I'm thinking in something
> like this:
>
> create table images (
> id serial primary key,
> title varchar not null,
> photo_id oid
> );
>
> select title, snapshot(photo_oid, 120, 120) as snap from images
>
> In this case, the snapshot function returns the resized snapshot of the original
> image.


Why not store the resized image in another column? Retrieval would
probably be more efficient than running an algorithm over each image
every time you wanted to fetch the "snapshots" (thumbnails?).

> I think that the core of function could be similar to this:
> 1) Obtain the image
> 2) Resize the Image to new size
> 3) Return the Resized Image
>
> Do you know if there exists a function like this ("snapshot")?


Not in the standard PostgreSQL installation.

> Otherwise, What is the type returned by the function ? What suitable procedure
> language should I use ? What image library for the redimension ?


I'd probably make the return type bytea. I'm sure several of the
procedural languages (PL/Perl, PL/Tcl, PL/Python) have modules that
interface to graphics libraries that can resize images; check their
respective web sites (CPAN for Perl, etc.). If I had to write this
function I'd probably use C and ImageMagick, but I'd be more likely
to generate the thumbnails on the client side and store them in
another column.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-10-2008, 01:35 AM
Juan Miguel
 
Posts: n/a
Default Re: Resizing images contained in oid fields

Michael Fuhr wrote:

>On Mon, Mar 21, 2005 at 05:12:52PM +0100, juanmime@ono.com wrote:
>
>
>>I have a table where an oid field is used for saving images. I'm thinking
>>about getting a little snapshot of all images without downloading the full
>>images. I only want to download some entire images. I'm thinking in something
>>like this:
>>
>>create table images (
>> id serial primary key,
>> title varchar not null,
>> photo_id oid
>>);
>>
>>select title, snapshot(photo_oid, 120, 120) as snap from images
>>
>>In this case, the snapshot function returns the resized snapshot of the original
>>image.
>>
>>

>
>Why not store the resized image in another column? Retrieval would
>probably be more efficient than running an algorithm over each image
>every time you wanted to fetch the "snapshots" (thumbnails?).
>
>
>
>>I think that the core of function could be similar to this:
>>1) Obtain the image
>>2) Resize the Image to new size
>>3) Return the Resized Image
>>
>>Do you know if there exists a function like this ("snapshot")?
>>
>>

>
>Not in the standard PostgreSQL installation.
>
>
>
>>Otherwise, What is the type returned by the function ? What suitable procedure
>>language should I use ? What image library for the redimension ?
>>
>>

>
>I'd probably make the return type bytea. I'm sure several of the
>procedural languages (PL/Perl, PL/Tcl, PL/Python) have modules that
>interface to graphics libraries that can resize images; check their
>respective web sites (CPAN for Perl, etc.). If I had to write this
>function I'd probably use C and ImageMagick, but I'd be more likely
>to generate the thumbnails on the client side and store them in
>another column.
>
>
>

Tanks Michael,

This example is a simplification of the problem. I know that a good
solution could be adding a column where storing the resized image. And I
think that a solution, could be creating a trigger, lauched before
insert or update, that autogenerate the thumbnail.

The new function could looks like this:
create or replace function createthumbnail (oid, integer, integer)
returns oid as ' ......';

The params will be (oid of the big image, width, height) and returns the
oid of the resized image.

and after. I will create the trigger that uses this function.

It is the best solution that I'm found.But there are two problems:
*) What happend if the size will be dinamically selected by the client
application ?
*) We need two oids per image (big and resized).

Anyway, in my scene, the thumbnails dimensions will be constant, and the
DB only will store a few hundred of images.

I think to program the image using the gd_lib library in "c". But I
think that this library needs the image file for reading, or for
writting. Because I'm using oids, I still don't know how to stablish
this match...Phereaps I need a library that reads/writes from/to a
buffer instead from/to a file.

Thanks Michael... If you are interented, I will send you the function/s
when I will finish.


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 08:34 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com