phpgroupware-developers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-developers] New image loading code


From: Dan Kuykendall (Seek3r)
Subject: [Phpgroupware-developers] New image loading code
Date: Sun, 30 Dec 2001 00:49:16 -0800

I have finally finished making the changes to how we handle find_image()
and image() in the common class as well as added a new image_on()
function.
First, for find_image() I have both improved performance and
functionality. Performance increases have been gained as previously
mentioned by just getting entire directory listings, storing them into
memory and just using isset to find out if the file exists.
One of the new features of this function is that now you only need to
pass it the image name without the extension. So instead of
'myimage.gif' you just send it 'myimage' and it will automaticly check
for myimage.png and if not there checks for myimage.jpg and if not there
checks for myimage.gif, and if no match is found then it will look for
myimage in case you did pass the extension the last one will make the
match.
This finally allows us to use PNG or JPG files for any and all images as
we choose. The reason to get away from gif's are covered in
http://www.gnu.org/philosophy/gif.html

The new function image_on() is a handy tool that works similair to
image(), but image_on() has an additional param.
image_on($appname, $imagename, $extension)

example:   $image_hover = $common->image_on('calendar', 'plus_sign',
'_over')

This function will check to see if plus_sign_over.png/jpg/gif exists and
if not then look for plus_sign.png/jpg/gif and return that instead.
This allows for template sets that dont have images for some hovering
events or whatever. For a real example of me using this look at
phpgwapi/templates/idsociety/navbar.inc.php around link 102

if ($GLOBALS['phpgw_info']['flags']['currentapp'] != 'home')
{
  $var['welcome_img'] =
$GLOBALS['phpgw']->common->image('phpgwapi','welcome2');
  $var['welcome_img_hover'] =
$GLOBALS['phpgw']->common->image_on('phpgwapi','welcome2','_over');
}
else
{
  $var['welcome_img'] =
$GLOBALS['phpgw']->common->image_on('phpgwapi','welcome2','_over');
  $var['welcome_img_hover'] =
$GLOBALS['phpgw']->common->image('phpgwapi','welcome2');
}

You will see that I am alternating based on if the current app is the
home page. If no then I show the normal welcome2 image with
welcome2_over (using image_on to make sure its there). But if it is the
home page then it switches them so that what would normally be the hover
image, welcome2_over is the default image and the normal default image
welcome2 is now used as the hover image. This helps make the page feel
more context sensative and helps remind the user what page he is looking
at.

I suggest everyone take a look at how I changed idsociety to make use of
the functions and at the very least please use the image() and
image_on() functions to stop forcing .gif in all of our code. The
functions should perform very well, and have made some noticible
improvements in disk activity on my test boxes.

Seek3r



reply via email to

[Prev in Thread] Current Thread [Next in Thread]