Marcel Eichner // Ephigenia

  • Home
  • Illustration
  • Code
  • Kontakt

Aktuelle Projekte

Horrorblog.org
jQuery.slideShow
Franklin
code.marceleichner.de

This Blog-Website is built with Harrison!

Blogs & Freunde

Gimmixx
Martin Fleck
Torsten Bergler
Jens Franke
Robokid
Peter Kröner
Polycoder
Coding Horror
Lotterliebe
CodeBalancer
Pseudocoder
Migrador
Dachdeckermeister Peter Arold in Werda, Plauen, Hof und Umgebung La Petite Provence - Pension und Festsaal in Leisnig Piv-Berlin, Immobilienverwaltung Verwaltung Berlin blogoscoop

#507

04.07.2011 19:51
0 Kommentare
Share
  • php
  • apache
  • gd-lib
  • image
  • server
  • nginx
  • static
  • content
  • delivery
  • .htaccess
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):

#461

15.06.2009 10:40
2 Kommentare
Share
  • code
  • wordpress
  • tip
  • apache
  • htaccess
  • mod
  • rewrite
Gerade wurde ich wieder gefragt wie man erfolgreich subdomains mit einer htaccess Rule erkennen kann. Grund dafür war das neue Update von Wordpress, nach dem die Subdomains nicht mehr so recht wollten.
Viele kenen die normalen Standard Rules für die htaccess Dateien und kennen noch nicht die Konditionalen Rules die auch sehr hilfreich sind.
RewriteCond %{HTTP_HOST} ^(subdomain1|subdomain2).domain.de$ [NC]
RewriteRule ^(.*)$ http://www.domain.de//$1 [R=301,L]
Diese müssen dann vor die Regeln von Wordpress und schon müsste es wieder laufen.

#270

06.01.2006 22:36
2 Kommentare
Share
  • seele
  • SPAM
Jaja, die lustigen spam bots
sorry für die Leute die heute abend n paar (ich hoffe nur so äh 10) emails bekommen haben. Trotz htaccess sperre konnt ick se nich abhalten und würde am lieben ja jeden kontrollieren per eingabecode oder so. da ich aber auf die freiheit stehe, und ein code zum eingeben würde nur noch leute abhalten.
Wer weiss wie sich das alles noch weiterentwickelt. Nur zu info - diese bots - die euch emails schicken, versuchen auch (nur anders) auch alle Gästebücher, Kommentareingaben, eigentlich jedes Formular was es im Internet gibt vollzuspammen mit links und bescheuerten kommentaren nur um ihren pagerank oder sonstwas zu steigern.
In Zukunft (ungewiss) wird es aber von mir hier (in meinem tiny system) filter geben die hoffentlich besser funktionieren.
Also habt verständnis für nen armen kleinen.
marceleichner HTML5 Harrison Theme (Validate Source), © 2010 by Ephigenia M. Eichner, Impressum