rejetto forum

thumbnails on the fly

SamePaul · 34 · 15186

0 Members and 1 Guest are viewing this topic.

Offline r][m

  • Tireless poster
  • ****
    • Posts: 347
    • View Profile
@SamePaul
I also serve some images (some very high res) from time to time.
Actually I'd be interested to "see" your solution/method for images.
Anything to make the process quicker/more efficient.
Would you share it here on the forum?

Edit:
As additional info
Firefox, Opera, IE, & Safari (recent/new release) test to work with ~mysection
however, Ephipany on Linux, as one that comes to mind does not. Likely there are others.
All tested so far work with diff tpl.
« Last Edit: August 08, 2010, 04:50:33 PM by r][m »


Offline SamePaul

  • Occasional poster
  • *
    • Posts: 72
    • View Profile
Diff tpl applies to subfolders here, at least where all are real.
Maybe you are right and I just misinterpret the way diff template works.

The main idea originally was to execute some console tool, which resizes image to specified size and the dumps JPEG data to stdout. Then HFS takes this output and send it to client.

So I build template:
Quote
...
[file.jpg=file.png=file.gif=file.bmp|private]
...
<a href="%item-name%"><img src="%item-folder%/~thumbnail?file=%item-name%" /> %item-name%</a>
...

[thumbnail]
{.add header|Content-Type: image/jpeg.}
{.exec|resize.exe "%item-resource%{.?file.} -scale 50x50"|out=x.}{.^x}

So basically if everithing works as expected, URL http://mysite.com/photos/july2010/~thumbnail?file=IMG_200.JPG would open as thumbnail version of file http://mysite.com/photos/july2010/IMG_200.JPG

Advantages:
- works on the fly with any picture you have on your server, including newly uploaded
- doesn't use diskspace
- works on any VFS

Disadvantages:
-relatively slow if you have lots of files in folder (thus not suitable if you have high hit rate)
-it doesn't work :) when I attempt to open the mentioned URL I get error 404 Not Found.

Another solution (proposed by rejetto) was to create thumbnail cache on disk and in template create thumbnails on the fly only when absent in cache. Finally template would look like this

<a href="%item-name%"><img src="/cache/%item-name%" /> %item-name%</a>

Of course it needs some polish (my is more complex), but it's just example to introduce principle.

Advantages:
-works on the fly
-it actually works(!!)
-consequent requests are pretty fast, as HFS takes thumbnails from cache
-spares disk reads

Disadvantages:
-takes diskspace (not a much however)
-in case of name conflicts there is no automatic way to resolve it
-requires additional hidden VFS share (which is not really a problem)

For image scaling I use ImageMagic tool set, which is pretty fast. However I'm going to write my own tool, because I need it to be even faster :)  pipelined and more suitable for my specific task.
« Last Edit: August 08, 2010, 05:54:39 PM by SamePaul »


Offline legop3

  • Occasional poster
  • *
    • Posts: 9
    • View Profile
is there an easy way to apply "on the fly" thumbnails to my template?


Offline dj

  • Tireless poster
  • ****
    • Posts: 291
  • 👣 🐾
    • View Profile
    • PWAs