PHP Image Rendering Library
by Marten van Wezel, Flying Weasel Mobile
Original idea by Marco van Hylckama Vlieg
Version 0.9.6 - 'The Michael Meyers version'
I haven't gotten round to writing up a proper 'licence' for this,
but the bottomline currently is:
- Don't claim that this is (just) your code
- Use it for whatever wish, modifications/patches are welcome.
- I would appreciate an 'image library by .. ' mention in some
'about.html' page, but I won't try to force you.
- Anything bad that happens is not my fault, I make no promises that
this program is fit for anything, neither can I guarantee that
there are absolutely no security holes.
Requirements:
- Imagemagick (convert & identify)
- jpegoptim (http://freshmeat.net/projects/jpegoptim/)
- gifsicle (http://www.lcdf.org/gifsicle/)
- (and PHP enabled to allow execution of binaries)
Features:
- Resizing to device capabilities, or half screen width, quarter width
- Logo mode with colormap optimization
- Multi-iteration smart resizing (into max bytes requested)
- Adding image canvas
- Source filename guessing (dynamic transcoding)
- Fallback image ('image not found') when no file present.
Bugs/Todo
- Right now certain parts need to be cleaned up. I use a few too
many 'binaries'. Where I could've done it in PHP.
- There's a lot of hidden functionality in the class, I just haven't
gotten round to officially enabling it.
- More in/output file formats, WBMP is urgent. Easy to add, really.
- Removing gifsicle/jpegoptim from the equation. They do improve
the final image quality vs size ratio..
- Security needs a once-over. I strongly doubt you can run an
injection attack, assuming the rest of your code doesn't allow
too weird filenames, but it Im not making promises.
- Support for imagemagic php module or perhaps the built-in gd libraries.
usage:
1: Copy(move) the file mshow.php to somewhere in your web tree.
2a: (unsupported) link images directly:
/mshow.php?idir=album&key=usernamedir&image=test.jpg&scale=large&type=jpg
2b: Create apache rewriterules to point to this mshow:
For keyed subdirs (../somedirtype/somesubtype/filename)
# $1 $2 $3 $4 $5 $6
# http://site.com/mpics/album/400/102934934_huge.jpg
RewriteRule /mpics/(.*)/(.*)/(.*)_(.*).(gif|jpg|jpeg|png)
/mshow.php?idir=$1&key=$2&image=$3.$5&size=$4&type=$5&rule=1
For the simpeler mode:
# http://site.com/mpics/images/image_large.jpg
RewriteRule /mpics/(.*)/(.*)_(.*).(gif|jpg|jpeg|png)
/mshow.php?idir=$1&image=$2.$4&size=$3&type=$4&rule=2
Notes:
- 'obviously' the first parameter gives the request name,
relative to the root of your website.
- The second parameter rewrites this to a command for mshow.php
$idir : the directory with all original images
default: images
(note: the cachedirs will always be $idir_cache)
$key : subdir of the images dir
$exp : the expiry for the cache measured in seconds
use -1 for infinite (generated once, cached forever)
use 0 for no cache (only use this for debugging, re-resizes
your image every fetch!)
default: -1
$scale : what kind of image do we want.
full give me the image at max resolution (regardless of
if the phone can handle this!)
large iterate a few times to get juuust below 10k
medium half the phone's width
small 1/4 the phone's width
default: large
$size : if you want to specify a max filesize (in bytes) other
than 'max image size' from wurfl
3: Edit the config.php for some sensible defaults. (obviously make
sure the dirs you mention in config to actually be present)
4: Create a file imagedir/images/unknown.gif that contains an
'image not found' image. (The imager will display this if the
requested image isn't there)
5: Call your image: http://site.com/mpics/album/400/test_large.jpg
- the imager will attempt to fetch (assuming defaults)
imagedata/albums/400/test.jpg with imagesize 'large'
Download here.
|
|