Get the width and height of an image using a function in PHP


This is a very useful function in PHP. PHP provides function to get the width and height of an image. The
getimagesize() function will determine the size of image file including flash file(swf).

Syntax

list($width, $height, $type, $attr) = getimagesize(“image_name.jpg”);

Code

This is a sample code, change image_name to your image name and test it!

<?php

list($width, $height, $type, $attr) = getimagesize(“image_name.jpg”);

echo “Image width ” .$width;
echo “<BR>”;
echo “Image height ” .$height;
echo “<BR>”;
echo “Image type ” .$type;
echo “<BR>”;
echo “Attribute ” .$attr;

?>

When you run this script you will see the result like this

Image width 379
Image height 344
Image type 2
Image attribute width=”379″ height=”344″

You will get the width, height, type of an image and also attribute of an image, I use this function in my image

upload form.

Type of an image you can see from table below You can read a full manual here

Type of the image
1 = GIF      5 = PSD          9 = JPC     13 = SWC
2 = JPG     6 = BMP     10 = JP2     14 = IFF
3 = PNG   7 = TIFF(intel byte order)               11 = JPX     15 = WBMP
4 = SWF   8 = TIFF(motorola byte order)     12 = JB2     16 = XBM

How to add date picker in joomla site…


In your component html file, put the following code at the top of your function:

JHTML::_('behavior.calendar');

Then for your date field in your form:

input class="inputbox" type="text" name="startdate" id="startdate" size="25" maxlength="25" value="" &
input type="reset" class="button" value="..." onclick="return showCalendar('startdate','%Y-%m-%d');"

How to determine if the user is viewing the Joomla front page or not?


If you are using Joomla older version like 1.0 then you’ll only need to verify the current component with the following command:


if ($option == 'com_frontpage' || $option == '') {
echo 'This is the front page';
}

Bellow porsion for Joomla! 1.5 could be easily confirmed by the following command:


if ( JRequest::getVar('view') === 'frontpage' ) {
echo 'This is the front page';
}

Just in case the above command doesn’t work then the issue could be a little more complicated and need to check if the current active menu item is the default one. I saw this issue in some 1.5 early versions.


$menu =& JSite::getMenu();
if ($menu->getActive() == $menu->getDefault()) {
echo 'This is the front page';
}

Adding custom columns/fields to Joomla article


Today we will learn how to add more columns/fields to Joomla *_content table. At first we should have to add a column in *_content table.
Run in for instance phpMyAdmin.
ALTER TABLE `jos_content` ADD `test` VARCHAR( 255 ) NOT NULL

Edit administrator/components/com_content/models/article.xml add:

In the first params section for instance below the access entry. Add var $test = null; to libraries/joomla/database/table/content.php
Now add $form->set('test', $row->test); to editContent() in administrator/components/com_content/controller.php
The result is that you now have a new field called test that can be used in various ways to display a separate text that is not a part of the article.