New cool image-PHP-script, which can be used from every programming language

I just wrote a new set of cool image-functions and a small script to automatically invoke and cache stuff it generates.

The script is able to do smart resizes, resizes, padding, rounded edges, caching, equal sizes, set quality and dynamically output in different support formats (jpeg, png, bmp, wbmp, gif etc).

To start with an example, I have uploaded a picture (”kasper_test_blog.jpg”) and symlinked to the script, so I can call it. It is a picture of me holding a speech at the 2007 OpenSource Days conference. I now want the same width and height + rounded edges on the picture. I set src of an <image> to “image.php?picture=temp/kasper_test_blog.jpg&equaldim=true&edgesize=35&bgcolor=000000&force=true&width=400&padding=15&paddingorigsize=true” resulting in:

This will:

  1. Make the width and height the same size because of “equaldim=true”.
  2. Make 35 size rounded corners because of “edgesize=35″.
  3. Use black as the backgroundcolor for everything because of “bgcolor=000000″.
  4. Not use cache because of “force=true”.
  5. Force the width to 400 pixels because of “width=400″ (could also have used “height=400″).
  6. Make 15 pixels of padding on top, bottom, left and right because of “padding=15″ (still using black as color for the padding because of “bgcolor=000000″).
  7. When using padding, instead of increasing the image-size by the padding, it will keep the original size because of “paddingorigsize=true”.

Other possible parameters are:

  1. “quality=85″ – sets a specific quality of the outputted image. Good when using it for a lot of thumbnails.
  2. “type=jpg” – output the image as JPG (default is PNG). Could also be “type=bmp”, “type=gif”, “type=png”, “type=wbmp” or whatever.
  3. “smartsize=200″ – makes the width or height to 200 – based on which is the larger one. Great for handling sizes on a personal gallery.

The sourcecode for the script and its framework can be found here:

  1. http://knjphpframework.kaspernj.org/scripts/image.php
  2. http://knjphpframework.kaspernj.org/functions_knj_picture.php
  3. http://knjphpframework.kaspernj.org/functions_knj_picture_bmp.php

Leave a Reply

You must be logged in to post a comment.