Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Better solution I usually go for: Create the thumbnails dynamically when needed, not upon upload.</p> <p>You create a script that generates thumbnails on the fly, and all your image tags point to this script:</p> <pre><code>&lt;img src="/thumbnail.php?image=foobar.jpg&amp;size=150" /&gt; </code></pre> <p>This delays the thumbnail generation until it is needed and works "asynchronously". With some .htaccess rewrite magic you can even make it look like a normal image file and cache images in a way that the Apache server will serve them the next time without invoking the script.</p> <hr> <p>To be a little more detailed, I use this for user profile images:</p> <p>Image tags:</p> <pre><code>&lt;img src="/img/users/123456/50.jpg" /&gt; </code></pre> <p>.htaccess:</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On # Rewrites requests for user images to match directory structure. # E.g.: URL /img/users/123456/50.jpg -&gt; /img/users/123/123456/50.jpg # Intermediate directory level is introduced to avoid cramming too many directories into the same directory. RewriteRule ^img/users/(\d{1,3})(\d*)/(\d+\.\D+)$ img/users/$1/$1$2/$3 [nocase,last] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] &lt;/IfModule&gt; </code></pre> <p>This first of all rewrites image requests to a deeper directory structure. If the image exists, Apache will serve it as usual. If it doesn't, my regular application is invoked. In the app, I route <code>/img/users/...</code> URLs to a module that ends up with two pieces of information: the user id <code>123456</code> and the requested size <code>50</code>. It then generates a thumbnail roughly according to this logic:</p> <ol> <li>Find profile image for user <code>123456</code></li> <li>Generate thumbnail in requested size</li> <li>Write thumbnail to <code>/img/users/123/123456/50.jpg</code>, where it will be picked up by Apache next time</li> <li>Output image</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload