rejetto forum

Software => HFS ~ HTTP File Server => Topic started by: SamePaul on August 05, 2010, 07:18:57 AM

Title: thumbnails on the fly
Post by: 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.

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.
Title: Re: thumbnails on the fly
Post by: rejetto on August 05, 2010, 07:34:14 AM
I guess it is not really right place to ask question, but can't create new topic.

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?

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>

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.
Title: Re: thumbnails on the fly
Post by: SamePaul on August 05, 2010, 08:03:35 AM
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.
Title: Re: thumbnails on the fly
Post by: rejetto on August 05, 2010, 11:08:11 AM
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.
Title: Re: thumbnails on the fly
Post by: SamePaul on August 05, 2010, 11:45:08 AM
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%".}

HFS will generate the following HTML
Quote
...
<img src="picture1.jpeg/~thumbnail" />
...
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"?
Title: Re: thumbnails on the fly
Post by: rejetto on August 05, 2010, 12:59:23 PM
did you consider the part where i said
you should consider this is a very heavy task, this way of doing is not suited.

this will kill your computer.


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

Empty. As i said you in my previous post, you just need to
{.exec|print_some_html.exe|out=x.}{.^x.}
Title: Re: thumbnails on the fly
Post by: rejetto on August 05, 2010, 01:03:50 PM
will consider for the future a command like this
{.image|src=file|width=x|dst=outfile.}
because it should be possible with very few lines
Title: Re: thumbnails on the fly
Post by: SamePaul on August 05, 2010, 01:30:59 PM
did you consider the part where i said
this will kill your computer.
Of course I consider and it is good solution. Here is trade off, however, because once thumbnails are created they become visible in HFS as well and their displaying will cause creation of thumbnails of thumbnails recursively. This can be solved of course, but solution becomes less trivial than it seems.
About killing computer i wouldn't really worry. Firefox usually pipelines ~10-20 requests to server. Running 20 lightweight resizers simultaneously won't be tremendous hit... unless you use Photoshop for this purpose :)

Empty. As i said you in my previous post, you just need to
{.exec|print_some_html.exe|out=x.}{.^x.}

Ok, that's fine. Also, I think there is problem to invoke [section] on file.
For example, if I enter URL http://mysite.com/somefolder/picture1.jpeg/~thumbnail HFS will rather return error, than execute [thumbnail] section. :(
Title: Re: thumbnails on the fly
Post by: SilentPliz on August 05, 2010, 02:13:28 PM
Firefox usually pipelines ~10-20 requests to server. Running 20 lightweight resizers simultaneously won't be tremendous hit... unless you use Photoshop for this purpose :)

Running 20 lightweight resizers simultaneously ...  performing their task on the client side.

People on your site will not tell you thank you.   ;)

To get an idea, put this in the default template, and browse to a folder containing twenty photographs (*.jpg).

[file=folder=link|private]
   <tr class='{.if not|{.or|{.get|can delete.}|{.get|can access.}|{.get|can archive item.}.}|non.}selectable {.if|{.mod|{.count|row.}|2.}|even.}'><td>
  {.if|{.get|is new.}|<span class='flag'>&nbsp;<BLINK>{.!NEW.}</BLINK>&nbsp;</span>.}
  {.if not|{.get|can access.}|<img src='/~img_lock'>.}
  <a class='the-item' href="%item-url%"><img src="%item-icon%"> %item-name%</a>
  {.if| {.?search.} |{:{.123 if 2|<div class='item-folder'>{.!item folder.} |{.breadcrumbs|{:<a href="%bread-url%">%bread-name%/</a>:}|from={.count substring|/|%folder%.}/breadcrumbs.}|</div>.}:} .}
{.switch|%item-ext%|,|jpg,gif,png,ico,bmp|
<table>
<a href="%item-url%" target="_blank" >
<fieldset>
<center><IMG alt="" src="%item-url%" style="width="120"; height="100"; border="5";</a></center>
</fieldset>
</table>
.}

{.123 if 2|<div class='comment'>|{.commentNL|%item-comment%.}|</div>.}
Title: Re: thumbnails on the fly
Post by: SamePaul on August 05, 2010, 02:30:41 PM
Running 20 lightweight resizers simultaneously ...  performing their task on the client side.

People on your site will not tell you thank you.   ;)
You are so sure. Pity you are not so right. ;)
Little piece of advice: don't dismiss user's requirements and don't substitute it with own.

Task is performed at correct side according to requirements and usage model.

<center><IMG alt="" src="%item-url%" style="width="120"; height="100"; border="5";</a></center>

specially for you again
Quote
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.
Title: Re: thumbnails on the fly
Post by: rejetto on August 05, 2010, 02:41:00 PM
99.9% of systems out there save to file the result of the resizing, just the first time. Other times the result (the thumbnail) is simply accessed.
This way will spend like 2% of your hard drive space and will free like 80% of your CPU.
And i will not mention disk activity, being that for every 50kb thumbnail you will avoid reading the 1000kb full size version to resize it.
Doesn't this sound like a good option?
Title: Re: thumbnails on the fly
Post by: rejetto on August 05, 2010, 02:43:20 PM
Ok, that's fine. Also, I think there is problem to invoke [section] on file.
For example, if I enter URL http://mysite.com/somefolder/picture1.jpeg/~thumbnail HFS will rather return error, than execute [thumbnail] section. :(

you should consider accessing /folder/~thumbnail?file=picture1.jpeg
and then using {.?file.} to know the file
Title: Re: thumbnails on the fly
Post by: SamePaul on August 05, 2010, 03:10:08 PM
99.9% of systems out there save to file the result of the resizing, just the first time. Other times the result (the thumbnail) is simply accessed.
This way will spend like 2% of your hard drive space and will free like 80% of your CPU.
And i will not mention disk activity, being that for every 50kb thumbnail you will avoid reading the 1000kb full size version to resize it.
Doesn't this sound like a good option?

As I said previously, it is definitely good solution worth of consideration. I just have another scenario which requires true dynamic thumbnail generation and for this task I insisted to clarify alternative solution. I was sure that HFS is capable of performing complex tasks, but my experience with templates is very limited.

you should consider accessing /folder/~thumbnail?file=picture1.jpeg
and then using {.?file.} to know the file

awesome! this would do the charm. Thank you very much!
Title: Re: thumbnails on the fly
Post by: SilentPliz on August 05, 2010, 03:33:31 PM
You are so sure. Pity you are not so right. ;)
Little piece of advice: don't dismiss user's requirements and don't substitute it with own.

You're right.

Given the level of understanding, it is better that I should give my point where my contributions are understood.

Thank you anyway for the advice.

bye!
Title: Re: thumbnails on the fly
Post by: TSG on August 06, 2010, 11:07:03 AM
If this is about HFS, I have seen it done using our TPGen http://www.rawr-designs.com/projects/tpgen/index.html

I really wish Giant Eagle would write a readme about how to use the command line operations for it.

I am not sure if it keeps re-making them or checks to see if they already exist. I know it can create only thumbnails/previews from 'new' images that don't already have it... but not sure about how it works through command line. Something for Richard to consider if he ever upgrades it some more.
Title: Re: thumbnails on the fly
Post by: SamePaul on August 06, 2010, 11:50:52 AM
Yes, I saw this a while ago. But it required manual building of thumbnails with specially provided tool. Maybe it has changed since then, didn't really check it lately.
Title: Re: thumbnails on the fly
Post by: SamePaul on August 06, 2010, 07:15:46 PM
you should consider accessing /folder/~thumbnail?file=picture1.jpeg
and then using {.?file.} to know the file

experimented a bit with this and unfortunately this is not really working.
1) accessing /folder/~thumbnail gives "404 Not found" whereas /~thumbnail works
2) file's location is unknown when HFS process [thumbnail] section as well as folder url & path.

Also it is not clear how to apply 1st proposed solution with creating thumbnails on disk. How can I determine full path to file? Just giving %item-name% doesn't work since current directory is not where file exists.
Title: Re: thumbnails on the fly
Post by: SilentPliz on August 07, 2010, 01:32:19 AM
Hi !

It is rather difficult to answer you if every time you give us bits of information.
Try to explain what exactly you want to do, how you go about it, shows some snippets of code and a sample content of your section [thumbnail], so we can understand the context.

This may be vast, the use of thumbnails.
For a pictures gallery: Only with the template? On a separate HTML page? With a Flash applet, Java? in Ajax scripting?
Could you use thumblists XML? ...

Have an idea of the program that you use to generate the thumbnails can be useful to develop a strategy for the script, to distrib the result.

For your troubles with variables, know the context of use can help to understand why, and most certainly how integrate them into a script.

%folder%, %item-name%, %folder%%item-name%.xxx, %item-ext%, %item-resource% ...etc

The [thumbnail] section, if it behaves like a HTML page, may restrict the use of variables.

It is much easier to consider the wishes of users, if we do not have to guess them.

So, if you can tell us more ...

Title: Re: thumbnails on the fly
Post by: SamePaul on August 07, 2010, 01:24:46 PM
SilentPliz what can I say bro... maybe you will take a look at my previous messages? you'll find there everything: what it was about, code snippets, sample content of the section etc.
Especially the key point, that I quoted for you once, but seems you need to hear it again.. dunno.
I'll try to rephrase for you:

I want to AVOID SENDING WHOLE MULTY-MEGABYTE IMAGE OVER NETWORK. I want to send SMALL THUMBNAIL instead.

Don't know how make it any clearer.
Look, I really appreciate your efforts to be helpful. It maybe would make just a bit more sense to help in what user (me) wants, rather than in what you think is better for 99% of the world.
Title: Re: thumbnails on the fly
Post by: r][m on August 07, 2010, 03:31:31 PM
@SamePaul
I've read this thread coulpe of times, and like SP I really don't
clearly understand either.
This is what I do.
Create thumbnails (any good image software should do it).
Use diff tpl to create page of thumbnails, on that page thumbnail links
to full image with archive. Clicking the link shows full image in browser,
or check the archive check boxes to DL several at once?
If you want to be able to dump you images in a folder and it does the rest
automatically, create it yourself.
No one else has been able to, so far, with out creating a system overload.
The closest is what the RAWR team has done.
Title: Re: thumbnails on the fly
Post by: SamePaul on August 07, 2010, 04:05:32 PM
@SamePaul
I've read this thread coulpe of times, and like SP I really don't
clearly understand either.
Then seems rejetto is able to read my mind. Otherwise I can't explain how he was not just able to understand me, he also proposed 2 solutions. You definitely noticed them when you read the thread, right?

Now, if anyone knows way to get full local path to current %item-name% - please, tell me. I'd love to hear. Really.
Just please, no more "alternative solutions".  :)
Title: Re: thumbnails on the fly
Post by: SilentPliz on August 07, 2010, 04:21:19 PM
rather than in what you think is better for 99% of the world.

 ::)


%item-resource%  = c:\...

%folder%%item-name%   = /folder/filename
Title: Re: thumbnails on the fly
Post by: SamePaul on August 07, 2010, 04:36:17 PM
%item-resource%  = c:\...
a-muuuusing :) thanx man!

Maybe you know as well how to get only path? Lets say I have %item-resource%  = "c:\folder1\folder2\file.ext" and I need take only "c:\folder1\folder2\" part and append to it "preview/file.ext".
Title: Re: thumbnails on the fly
Post by: SilentPliz on August 07, 2010, 07:03:39 PM
Path without file.ext:


c:\folder1\folder2\
=
{.filepath|%item-resource%.}

Edit:

http://www.rejetto.com/wiki/index.php/HFS:_scripting_commands
Title: Re: thumbnails on the fly
Post by: bacter on August 08, 2010, 11:08:15 AM
If you want to do something like that:

(http://img822.imageshack.us/img822/5188/fotodemo.png)

Perhaps the following code may help you:

Code: [Select]
[file_foto]
<div style="width:150px; height:130px; overflow:hidden; float:left; font-size:9px; " title="%item-size% %item-modified%">
{.set|fn|{.replace|%20| |{.replace|/|\|%encoded-folder%thumbs/%item-name%.}.}.}
{.if|{.exists|{.^fn.}.}|
{:{.set|fn|thumbs/%item-name%.}:}|
{:{.if|{.pos|%item-ext%|.jpg.gif.bmp.png.}|
{:{.set|fn|%item-name%.}{.comment|******.}:}|
{:{.set|fn|.}:}
.}:}
.}
<a href="%item-url%"><div align="center">
{.if|{.^fn.}|
{:<img  height="110px;" src="{.^fn.}" />:}|
{:<img  style="border:35px solid transparent;" height="40px;"  src="%item-icon%">:}.}
</div>
<div style="background-color:#d0d0f8; color:black;">%item-name%</div></a>
{.if|%item-comment%|<div class="comment">{.^cmttxt.}</div>.}
</div>

I use this section when a folder should be presented as images. When no thumb exists, the full picture is used - i have placed there the {.comment|******.} because there is where you can place the exec to create the thumbnail.
Title: Re: thumbnails on the fly
Post by: SamePaul on August 08, 2010, 01:00:46 PM
SilentPliz thanks again. Now it works

bacter Thank you, but don't need it either for same reason I didn't want RAWR or Live: it's workaround which just makes something that looks like what I need, but not solution.

rejetto Do you think it will be possible in some future to run sections on arbitrary folder, not only on root? I mean, if I have [mysec] section in template, will URL http://mysite.com/some/folder/~mysec work?
Title: Re: thumbnails on the fly
Post by: SilentPliz on August 08, 2010, 01:59:40 PM
Quote
rejetto Do you think it will be possible in some future to run sections on arbitrary folder, not only on root? I mean, if I have [mysec] section in template, will URL http://mysite.com/some/folder/~mysec work?


I'm not sure of that.
But until an answer or solution from rejetto, you can use the template that includes [mysec] in folders of your choice as diff template, and keep the template without [mysec] as default template.

It's just an idea, don't be angry. :D

Edit:

It depends on the contents of your section, but you can also cut in your template your [section] and paste it in the diff template tab of "properties" of choosed  folders.
Title: Re: thumbnails on the fly
Post by: SamePaul on August 08, 2010, 02:45:14 PM
I'm not sure of that.

Actually it was his idea, so I hope he's going to make it work as well ;)
you should consider accessing /folder/~thumbnail?file=picture1.jpeg
and then using {.?file.} to know the file



But until an answer or solution from rejetto, you can use the template that includes [mysec] in folders of your choice as diff template, and keep the template without [mysec] as default template.
I guess it can work. However it will work for a specific folder added directly to VFS and only for it. Not even for subfolders, as the become inaccessible...

Anyway, I think that my phrase "picture gallery" mislead most of you, guys. I used this term only for example. My real objective is to preview any picture accessible via HFS. That's why I can't use "preprocessing" tools like TPGen.

It's just an idea, don't be angry. :D
Nah, I'm not that bad ;)
Title: Re: thumbnails on the fly
Post by: r][m on August 08, 2010, 03:55:45 PM
However it will work for a specific folder added directly to VFS and only for it. Not even for subfolders, as the become inaccessible...
Diff tpl applies to subfolders here, at least where all are real.
Title: Re: thumbnails on the fly
Post by: SilentPliz on August 08, 2010, 04:11:59 PM
r][m is right!  :)

Quote
Actually it was his idea, so I hope he's going to make it work as well ;)

you should consider accessing /folder/~thumbnail?file=picture1.jpeg
and then using {.?file.} to know the file

This already be working.



Title: Re: thumbnails on the fly
Post by: r][m on August 08, 2010, 04:31:58 PM
@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.
Title: Re: thumbnails on the fly
Post by: SamePaul on August 08, 2010, 05:50:12 PM
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.
Title: Re: thumbnails on the fly
Post by: legop3 on March 20, 2019, 12:57:27 AM
is there an easy way to apply "on the fly" thumbnails to my template?
Title: Re: thumbnails on the fly
Post by: dj on March 20, 2019, 04:23:50 AM
dnd_upload_thumb (http://rejetto.com/forum/index.php?topic=13077.msg1064110#msg1064110) generates thumbs on the fly on (dnd) upload