One problem when relaunching large projects with a ton of images is to re-create all the thumbnails that users have uploaded in the years. If you don’t use paperclip (ruby) or anything like it in PHP (is there any like it!?) where you can run run one command to re-create all the thumbnails in all specified sizes your can try to keep it flexible and create every image on demand.
Theory
The Webserver should serve the image if it exists. If the file does not exist, the request should be redirected to a PHP script that searches and creates the requested image file (in requested size) at exactly the location it was originally requested. The second request on the file will not be redirected to the PHP script and will server the image that now exists.
Practice
So the first thing to archive is to send the request of a not existing image to a PHP file. That’s easy if you’re familiar with all the nginx directives:
This rule can be combined with the anti-hotlinking rules for images with nginx I showed you last week.
After that we need to create a format that includes width and height of any requested image so that the thumbnailer.php
knows which size the created image should have. A valid request for a resized file should always have all parameters (width, height) in it:
../img/public/9c4be029/438xauto/filename.jpg
This makes it easy to split up width, height with a regexp in thumbnailer.php
. The following code is just an example. You’re surelly integrate the logic into your frameworks:
That’s it! After that you can request any image in any size on your webserver by only creating it once it’s requested.
There are some things you can add, like other parameters in the $formatRegexp
string to add different resizing methods or even filters, or limitations on the width
and height
parameter.
Appendix: Apache
It’s almost the same thing with apache. Just add a few lines to your .htaccess.
and all your image requests are redirected to the thumbnailer (or anything):
Auf dem LinuxTag 2010 hat Caspar die Vimperator Erweiterung für den Firefox Browser vorgestellt die ich mir zu Hause gleich zu Gemüte geführt habe.
Die Erweiterung ist total für Nerds gedacht. Man kann den kompletten Browser, alle Links und Befehle von der durch den Vimperator hinzugefügten Kommandozeile aufrufen. So bekommt man noch mal mindestens 100 Pixel in der Höhe Platz für die Websites und gerade auf Netbooks ist das eine Menge Platz!
Nach einer leichten Einführungsphase um die wichtigsten Befehle wie o www.spon.de[ENTER]
für Seite aufrufen oder t www.horrorblog.org[ENTER]
für Tab öffnen zu lernen hab ich mir mitlerweile die komplette Bedienung zugelegt und auch schon mein erstes "Plugin" geschrieben das mit die aktuelle URL mit Bitly als ShortURL in die Zwischenablage legt. Hier meine eigene .vimperatorrc
Datei die noch ein paar mehr Sachen macht:
" only use with buftabs plugin
set showtabline=0
" custom colorsheme
colorscheme darkness
" set textmate as editr
set editor="mate -w"
" show hover links in status bar
set showstatuslinks=2
js document.getElementById("status-bar").setAttribute("moz-collapsed", false);
" no error sound, just flash display
set errorbells visualbell
" alternative tab navigation
map b gt
map v gT
" tab navigation via arrow keys
map <Left> <C-p>
map <Right> <C-n>
map h <C-p>
map l <C-n>
" bit.ly shortener.
javascript <<EOF
shortenURLIsGd = function (url) {
var req = new XMLHttpRequest();
" get your username and api key from bit.ly!!!
req.open("GET", "http://api.bit.ly/v3/shorten?login=[Username]&apiKey=[API_KEY]&format=txt&longUrl=" + escape(url), true)
req.onreadystatechange = function (ev) {
if (req.readyState == 4) {
if (req.status == 200) {
util.copyToClipboard(req.responseText, true);
} else {
liberator.echo(req.responseText);
}
}
}
req.send(null);
}
EOF
map <silent> short :javascript shortenURLIsGd(buffer.URL);<CR>
map <silent> bitly :javascript shortenURLIsGd(buffer.URL);<CR>
Des weiteren sei noch erwähnt, dass man noch weitere ColorShemes oder Vimperator Plugins im Internet findet. Ein super Plugin ist auch das Buftabs Plugin, dass sogar die Tableiste überflüssig macht.
[UPDATE #1] Dank der Aktualisierung von Geshi, das das Code-Highlighting hier im Blog erledigt sieht das Vim-Script jetzt auch schön bunt aus.