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

Advertisements

Show/Hide multiple DIVs with Select using jQuery


Today ill discuss Show/Hide multiple DIVs with Select using jQuery. Bellow a complete example about that

<script type=”text/javascript”>
$(document).ready(function(){
$(‘.box’).hide();
$(‘#dropdown’).change(function() {
$(‘.box’).hide();
$(‘#div’ + $(this).val()).show();
});
});
</script>
<form>
<select id=”dropdown” name=”dropdown”>
<option value=”0″>Choose</option>
<option value=”area1″>DIV Area 1</option>
<option value=”area2″>DIV Area 2</option>
<option value=”area3″>DIV Area 3</option>
</select>
</form>
<div id=”divarea1″>DIV Area 1</div>
<div id=”divarea2″>DIV Area 2</div>
<div id=”divarea3″>DIV Area 3</div>

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';
}

OpenCart open source E-commerce solution


OpenCart is an open source PHP-based online shopping cart system. A robust e-commerce solution for Internet merchants with the ability to create their own online business and participate in e-commerce at a minimal cost.

OpenCart is designed feature rich, easy to use, search engine friendly and with a visually appealing interface.

Download link here

No Right Click


No Right Click – Disable the right click on your pages to prevent users from “borrowing” images from your site and viewing your page source!

Ever wanted to prevent users from “borrowing” images from your site through right-clicking them and “save image as…” or right-clicking the page and viewing your page source? The No Right Click will disable the right click on your page in just a few clicks. No programming knowledge needed!

Protect the content of your Web page by preventing others from viewing your source code!

Simply add the following code to the <BODY>  section of your web page (Press Ctrl C after selecting code to copy it):

<script language=JavaScript>
<!–
var message=”This website and it’s contents are owned and licensed by https://ranawd.wordpress.com.\nAll contents are copyrighted and are not available for download and/or use on any other site.\n\nAll Rights Reserved. © 2007-2008 https://ranawd.wordpress.com&#8221;;
///////////////////////////////////
function clickIE4(){
if (event.button==2){
alert(message);
return false;
}
}
function clickNS4(e){
if (document.layers||document.getElementById&&!document.all){
if (e.which==2||e.which==3){
alert(message);
return false;
}
}
}
if (document.layers){
document.captureEvents(Event.MOUSEDOWN);
document.onmousedown=clickNS4;
}
else if (document.all&&!document.getElementById){
document.onmousedown=clickIE4;
}
document.oncontextmenu=new Function(“alert(message);return false”)
// –>
</script>

Javascript validation check


There ate two javascript validation function i have made.

First one check empty field using id. We may use field id by an array as bellow. This function check empty field and if found empty field then focus that field also. We may use here another condition like email, phone number check. I think this will be reduce line number of code and time also.
Example:
<form method=”post” action=”<?=$_SERVER[‘PHP_SELF’]?>” onSubmit=”return checkClientForm();”>
<input type=”text” name=”name” id=”name” value=”” tabindex=”1″ /><br />
<input type=”text” name=”title” id=”title” value=”” tabindex=”2″ /><br />
<input type=”text” name=”description” id=”description” value=”” tabindex=”3″ /><br />
<input type=”submit” name=”submit” value=”Save” tabindex=”4″ />
</form>

Second one check file type like image. We may use this function by onchange element. If the file type dose not match then this will give a alert and clear the field also.

Example:
<input type=”file” name=”image” id=”image” value=”” onchange=”checkPhoto()” />

<script language=”javascript” type=”text/javascript”>
function checkClientForm(){
var cont;
var allid = new Array(“name”,”title”,”description”); //you may add more
var msg;
for (var i=0; i<=allid.length-1; i++){
cont=document.getElementById(allid[i]).value;
if(cont.length==0){
alert(“You should fill the required fields properly”);
document.getElementById(allid[i]).focus();
return false;
}
}
return true;
}

function checkPhoto(){
if( (document.getElementById(‘image’).value.split(‘.’)[1]!=’jpg’) && (document.getElementById(‘image’).value.split(‘.’)[1]!=’jpeg’) && (document.getElementById(‘image’).value.split(‘.’)[1]!=’JPG’) && (document.getElementById(‘image’).value.split(‘.’)[1]!=’JPEG’) && (document.getElementById(‘image’).value.split(‘.’)[1]!=’png’) && (document.getElementById(‘image’).value.split(‘.’)[1]!=’PNG’)){ alert(“Sorry, This type of file is not allowed to upload.”); document.getElementById(‘image’).value=”; document.getElementById(‘image’).focus(); return false; }
}
</script>