Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

a weird tclMagick/Image/SQLite question ...

15 views
Skip to first unread message

sp...@controlq.com

unread,
Aug 11, 2006, 3:31:36 PM8/11/06
to

This is for all you image gurus who have already been-there/done-that ...

Using tclMagick, I read a .jpeg image, resize it, preserving the aspect
ratio to create a thumbnail, and copy it to a photo image for display
purposes. As the file read/resize/copy operation is somewhat expensive,
I'd like to save the thumbnail as an SQLite BLOB, but the image size is
still pretty big (puts [string length [$img data]] reports over 150K for a
160x120 thumbnail).

What is the most efficient way of storing the image data in order for it
to be copied back and forth from a database? Do I need to compress and
perhaps then encode the data for efficiency? Should I be using the WAND
data and compression for the I/O rather than the final image data? As I'm
trying to avoid I/O and CPU cycles in the process, I'm looking for
efficiency gains ...

Thanks for any ideas or pointers.

Cheers,
Rob.


----== Posted via Newsfeeds.Com - Unlimited-Unrestricted-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---

Helmut Giese

unread,
Aug 11, 2006, 6:36:53 PM8/11/06
to
>Using tclMagick, I read a .jpeg image, resize it, preserving the aspect
>ratio to create a thumbnail, and copy it to a photo image for display
>purposes. As the file read/resize/copy operation is somewhat expensive,
>I'd like to save the thumbnail as an SQLite BLOB, but the image size is
>still pretty big (puts [string length [$img data]] reports over 150K for a
>160x120 thumbnail).
Hi Rob,
I am NOT an image guru but recently I was forced to do more image
processing than I wanted, so - here goes:
150k for such a small image really looks like a lot. Since its only a
thumbnail I would experiment with another graphic format
- export as GIF - I would expect it to be smaller
- export as jpeg - but with a higher degree of compression. This will
reduce the quality - but then: what quality do you expect/require of a
thumbnail?

>What is the most efficient way of storing the image data in order for it
>to be copied back and forth from a database? Do I need to compress and
>perhaps then encode the data for efficiency? Should I be using the WAND
>data and compression for the I/O rather than the final image data? As I'm
>trying to avoid I/O and CPU cycles in the process, I'm looking for
>efficiency gains ...

No idea wrt to these questions.

Just my 0.02 - wait, make that 0.01 :)
Best regards
Helmut Giese

Eric Hassold

unread,
Aug 11, 2006, 7:10:01 PM8/11/06
to
sp...@controlq.com a écrit :

> This is for all you image gurus who have already been-there/done-that ...
>
> Using tclMagick, I read a .jpeg image, resize it, preserving the aspect
> ratio to create a thumbnail, and copy it to a photo image for display
> purposes. As the file read/resize/copy operation is somewhat expensive,
> I'd like to save the thumbnail as an SQLite BLOB, but the image size is
> still pretty big (puts [string length [$img data]] reports over 150K for a
> 160x120 thumbnail).
>

Image content as returned from [$img data] is a very unefficient way to
store image data, since this is a list of pixels, and each pixel is
represented by a #RRGGBB (7 characters) value. Even if stored as
uncompressed RGB data, a 160x120 thumbnail requires 56kB (160*120*3).
Such a bytes array can easily be extracted from [$img data]:

# Get data as list of colors
set tkdata [$img data]
# Convert to hexadecimal string
set hexdata [string map [list " " "" "#" "" "{" "" "}" ""] $tkdata]
# And format it into a bytes array (RGB)
set bdata [binary format H* $hexdata]

Note that this raw data can be converted into a Tk image very quickly,
thanks to support for PPM in Tk core since 8.4.7 (no extension required):

set ppmdata "P6\n\# PPM data\n160 120\n255\n"
append ppmdata $bdata
set img2 [image create photo -data $ppmdata]

However, if you know that interpreter used to read those thumbnails will
incorporate support for more image formats than PPM and GIF (that is,
either Img or Pixane extensions will be available), saving thumbnails in
PNG or JPEG format is probably a simpler, more portable, and more
efficient way to go (a typical 160x120 photographic image wil be 35-40kB
in PNG format, 20-25kB in JPEG format).


Eric

-----
Eric Hassold
Evolane - http://www.evolane.com/

sp...@controlq.com

unread,
Aug 15, 2006, 11:49:45 AM8/15/06
to

Helmut, Eric,

Thanks for your input ... I now have a working prototype which I can
enhance from a performance standpoint and move forward.

0 new messages