imageProcessor - resize the image after uploading.
This script will process images at page load then cache it, instead of when you upload it in the cms.
This way, it's easier to change the wanted image size AFTER uploading all your images,
and also easier to make more than one size for a single image, to be shown at different places in the front-end.
PHP 5.3 with the GD extension enabled, Apache with rewrite module enabled and AllowOverride All.
<img src="/original_image_path.jpg?params" />
Any additional param will still be used in the resulting image name so it is possible (although not recommended) to prevent caching by adding a timestamp value.
* If none of the params listed above are used, the original image will be returned directly without any processing.
* If size param is given, the min/max params are completely ignored (maxw, maxh, minw, minh)
* If crop param is given, margins param is ignored
<img src="/images/logo.png?size=200x200&margins&bgcolor=0,0,0&quality=80&type=jpg" />
The above example will resize an image to exactly 200x200, adding black margins around the image if necessary to prevent image distortion, and converting to JPEG with a quality of 80.
<img src="/images/logo.png?size=200x200&crop=topright" />
The above example will resize an image to exactly 200x200, cropping either the top or the right side if necessary to prevent image distortion, keeping the bottom left corner always visible.
<img src="/images/logo.png?maxh=80" />
The above example will simply make sure that the resulting image has a height of 80 pixels of less. If the input image is more than 80px of height, it will shrink it down to 80 pixels of height, also shrinking the width, keeping the original ratio.
RewriteEngine On # ImageProcessor RewriteCond %{QUERY_STRING} . RewriteCond %{REQUEST_FILENAME}&%{QUERY_STRING} -s RewriteCond %{REQUEST_FILENAME}&%{QUERY_STRING} -f RewriteRule ^.*$ %{REQUEST_FILENAME}\%26%{QUERY_STRING} [NC,L] RewriteCond %{QUERY_STRING} . RewriteCond %{REQUEST_FILENAME}?%{QUERY_STRING} -s RewriteCond %{REQUEST_FILENAME}?%{QUERY_STRING} -f RewriteRule ^.*$ %{REQUEST_FILENAME}\%3F%{QUERY_STRING} [NC,L] RewriteCond %{QUERY_STRING} . RewriteCond %{REQUEST_FILENAME} -s RewriteCond %{REQUEST_FILENAME} -f RewriteCond %{REQUEST_FILENAME} \.(jpg|JPG|jpeg|JPEG|png|PNG|gif|GIF)$ RewriteRule ^.*$ /imageprocessor.sn [NC,L,QSA]
Written by Olivier Saint-Laurent, <olivier@sednove.com>
1.0 2016-05-19 pascale@sednove.com
Cras sit amet nibh libero, in gravida nulla. Nulla vel metus scelerisque ante sollicitudin commodo. Cras purus odio, vestibulum in vulputate at, tempus viverra turpis.
1.0 2014-09-09 21:24:14 laplante@sednove.com