Content last modified Monday 6 March 2017
hop to #bottom
Categories:
Author:
Current version:
0.1
About It:
Get it:
Rate it:
  • Helpful?
  • 5 Yes
  • 0 No
Flag it:

If you'd like to provide updated information and do not have access to directly edit, please contact the site admin; thanks!

lam_dynamic_image

download here: v0.1 lam_dynamic_image.zip (includes 3rd party image.php script and lam_dynamic_image.txt)

lam_dynamic_image (on-the-fly image resizing and display)

This plugin allows you to output and resize article images (and images) on-the-fly. It also caches your resized images for better performance. The cached images are kept and stored for 7 days (configurable in ‘image.php’ file) before they are automatically cleared if not viewed within that time.

lam_dynamic_image will use Imagemagick if available on your host (apparently its quicker/better/more efficient?), otherwise it will use the slower GD library. This plugin is not a substitute for professional imaging software as you will always get much better results just resizing in Adobe Photoshop and the like.

Requirements:

You may notice performance hits as resizing images via PHP (especially large dimension images) is rather memory-intensive. the caching done with this plugin should alleviate this issue but each image still has to be processed at least once. If the images don’t show up for you, try resizing a smaller sized image to see if that works. If it does, then your host most likely hasn’t alloted you enough memory for php to use.

Usage:

  1. Copy the included “image.php” file right into your /images directory (or whatever directory you use for your images) (EDIT as this may introduce potential security risks throwing a php script into a readable/writable directory you are welcome to place it anywhere you wish instead. the plugin code is also pretty simple to edit to reflect this. my next version will hopefully just include the entire script straight into the plugin so one wouldn’t have to worry about this)
  2. Create a directory within your image directory called “cache” and make sure its readable/writable

Tags:

<txp:lam_article_image />

Uses same attributes as txp:article_image /> (minus the align and inline style attributes) plus the following optional values (you can, but certainly don’t need to specify both):

  • height – specifies maximum height of resized image. example height="200" (leave out ‘px’)
  • width – specifies maximum width of resized image. example width="200" (leave out ‘px’)

if height and width are omitted, the tag will just output your article image using its original size.

hint: you can still use thumbnail attribute – specify 0 or 1. This will output the regular sized thumbnail for the image created by Textpattern.

<txp:lam_image />

Uses same attributes as txp:image /> (minus the align and inline style attributes).

Examples:

<txp:lam_article_image width="450" /> will resize and output article image to a maximum width of 450 px. The height will automatically be calculated and resized proportionally. will output the following html <img src="http://siteurl.com/images/image.php?image=id.jpg&amp;width=450" />

<txp:image id="3" height="300" /> will resize and output the image with an id of “3” with a maximum width of 300 px. The height will automatically be calculated and resized proportionally. will output the following html <img src="http://siteurl.com/images/image.php?image=3.jpg&amp;height=300" />

Note: This plugin will only resize proportionally. While you can specify something like <txp:article_image width="450" height="450" /> it will not return an article image with dimensions 450 × 450. This plugin will simply resize the image until the largest height or width value does not exceed either height/width attribute. Useful if all of your images are not the same proportion but you need it to fit with your other images. Also, you cannot use this plugin to enlarge image dimensions (as that would be silly).

Credits

Firstly, thanks to Gerd Tentler (www.gerd-tentler.de/tools) for allowing me to include and modify his Thumbs-up script. I took a look at phpThumb but I personally didn’t need all of the features it provided. I simply wanted on-the-fly image resizing and display. The rest of the credit goes to the TXP dev team as all I did was take the <txp:article_image /> and <txp:image /> functions and modify them to make use of Gerd’s script.

TODO

  • include the 3rd party script directly into the plugin to avoid having to upload any files on your own (you lazy bums :) !)
  • include gocoms code to automatically create the cache directory within your images dir
  • generate the cached image more intelligently (currently generates an extremely unique filename like img_f5017ed08f83ff5a2a28910eaec06b5b_145×200.jpeg but should be just using textpatterns already unique image id’s)
  • make the plugin tags output the url of the cached image instead of <img src="http://siteurl.com/images/image.php?image=3.jpg&amp;height=300" />

Warning:

As this utilizes a 3rd party script I personally don’t know how secure it is. As far as I can discern it seems decent but its out of my current skill level to improve. I modified a few lines in there to add a bit of security but I am by no means a php expert!

Since the resize script uses the url for variables, your cache could be abused if a user were to manually enter different values for height/width repeatedly (as the script creates a cached version for each different size). A much better way would be to use the url of the cached image instead. its something i might look into (if i can actually do it) but for now, if anyone with better skills wants to improve on this (or know of a better script to use?) then by all means! i only offer this as a potential but definitely not perfect solution for on-the-fly resizing/display.

Testing:

Tested on php5+ but should work for php 4.1+

Article Request Count:
Keywords/tags:
Posted here:
26 Dec 2007
Article modified:
17 May 2009

If there is a comment form at the Information URL, you may want to leave your comments/questions there or at the Forum thread for quicker feedback. Otherwise, comment away:

Your comment will NOT be submitted until you click the 'Submit' button on the next pageload.

Subscribe to this article's comments RSS feed. [ ? ]   View Recent Comments across the site.

You know you want to visit the Archives.

Browse

Categories


Articles

There are also tag clouds, 'cause those are fun.
Published with Textpattern