Software > HFS ~ HTTP File Server

thumbnails on the fly

(1/7) > >>

SamePaul:
I guess it is not really right place to ask question, but can't create new topic.

Anyway, the question is: is there any way to run some program and use it's output as data to be sent to client?
For example, I have pictures gallery and want to show them in with small thumbnails. On regular web-server I would write something like
<a href="pic1.jpeg"><img src="gen_preview.php?file=pic1.jpeg&height=30" />pic1.jpeg</a>

Maybe in HFS template I can do something similar? The ideal would be running utility on the fly and use its output. But if HFS can somehow run utility to generate thumbnail file during HTTP request, it is good too.

Using original size of picture is not an option, because pictures are hi-res and I have relatively narrow upstream. Moreover, cellular traffic is still limited.

rejetto:

--- Quote from: SamePaul on August 05, 2010, 07:18:57 AM ---I guess it is not really right place to ask question, but can't create new topic.

--- End quote ---

you must go the the board's topics index, there you'll find the "new topic" button.
it's a mess, so consider CTRL+F to find it in the page.


--- Quote ---Anyway, the question is: is there any way to run some program and use it's output as data to be sent to client?

--- End quote ---

yes, command {.exec.} does just that.
you'll find details at http://www.rejetto.com/wiki/index.php/HFS:_scripting_commands#Others


--- Quote ---For example, I have pictures gallery and want to show them in with small thumbnails. On regular web-server I would write something like
<a href="pic1.jpeg"><img src="gen_preview.php?file=pic1.jpeg&height=30" />pic1.jpeg</a>

--- End quote ---

you should consider this is a very heavy task, this way of doing is not suited.
my suggestion is to refer to the thumbnail as a simple file whose name is derived directly from the original file.
like src="preview/%item-name%"
same name, but in a sub-folder.
just, at the time of pointing this thumbnail, you ensure it exists, and in negative case you run the program that creates it.
{.if not|{.exists|preview/%item-name%.}|{:{.exec|resize.exe "%item-name%" "preview/%item-name%".}:}.}

this is just a draft of course.

SamePaul:
excellent! Thanks for link and explanation.

In case i want to use program output, how it is sent?
Lets consider the following template:

<img src="{.exec|test.exe "%item-name%".}" />

and output of test.exe is "123456789". How this data is transferred? How would look final HTML? My guess is:
<img src="12345678" />
am I right?

If so how can i emulate PHPish behaviour?  maybe I can write template like this:

<img src="%item-name%?section=thumbnail" />

[thumbnail]
{.exec|resize.exe "%item-name%".}

where resize.exe outputs jpeg data to stdout. will this work? Not sure if URL syntax is correct, but I guess you get the idea.

rejetto:
I think you are muddling a bit.

The output of the exec will never be the jpeg itself. The browser is not reading in "src" the data itself, but only the path to the file.
So, eventually the utility you run should return the path, and i guess that's not what it is doing.
You'll probably will have to specify yourself the path to the utility, so you'll just have to copy this path to the "src" as well.
The only case you are supposed to capture this output is to check if the utility completed its job as it was supposed to do.

You are able anyway to return the output to the browser, you'll have to do
{.exec|command.exe|out=x.}{.^x.}
that means put the output in x, and then give x.
currently there's no option to give the output directly without using the variable.

more, i don't understand why you try to use that [section], i don't think you have any need of it.

SamePaul:
I'm not muddling, but you just misinterpret. Why not jpeg itself? Application can output whatever it wants, right? :)

Again, here is part of template. Originally I made mistake, because I didn't remember syntax. Here how it should be


--- Quote ---...
<img src="%item-name%/~thumbnail" />
...

[thumbnail]
{.add header|Content-Type: image/jpeg.}
{.exec|resize.exe "%current-path%".}

--- End quote ---

HFS will generate the following HTML

--- Quote ---...
<img src="picture1.jpeg/~thumbnail" />
...

--- End quote ---
Now browser receives this HTML, it sees <img> tag and 'src'. Assuming, that addres of page is http://mysite.com/somefolder/ the browser now tries to fetch URL "http://mysite.com/somefolder/picture1.jpeg/~thumbnail" to load image.

If I remember correctly it will cause HFS to take section "thumbnail" from template, process it and the result return to browser.
Now, if I understand right, you say that {.exec.} will not cause HFS to replicate application's output to browser?

Lets consider another example. I have section in template
[mysection]
{.exec|print_some_html.exe.}


output of print_some_html.exe is always same:
<html>
<body>
Hello World!
</body>
</html>

Now I type in browser this address
http://mysite.com/~mysection

What will I see in browser? Empty page? "Hello World"?

Navigation

[0] Message Index

[#] Next page

Go to full version