Best image cropping on php


if($_GET['action']=='process')
{

$plugins_urls = plugins_url().'/myadmanager/thumb/';

move_uploaded_file($_FILES['imagelink']['tmp_name'], 'thumb/'.$_FILES['imagelink']['name']);

/******************************************* Resize ********************************/
$file_without_ext = preg_replace("/\.[^$]*/","",$_FILES['imagelink']['name']);
$file_with_ext=end(explode(".", $_FILES['imagelink']['name']));
if($file_with_ext=="jpg"){ $image = imagecreatefromjpeg($plugins_urls . $_FILES['imagelink']['name']); }
if($file_with_ext=="png"){ $image = imagecreatefrompng($plugins_urls . $_FILES['imagelink']['name']); }
if($file_with_ext=="gif"){ $image = imagecreatefromgif($plugins_urls . $_FILES['imagelink']['name']); }

$filename = 'thumb/'. $file_without_ext.'-resized.'.$file_with_ext;
$thumb_width = 150;
$thumb_height = 150;
$width = imagesx($image);
$height = imagesy($image);
$original_aspect = $width / $height;
$thumb_aspect = $thumb_width / $thumb_height;
if ( $original_aspect >= $thumb_aspect )
{
$new_height = $thumb_height;
$new_width = $width / ($height / $thumb_height);
}
else
{
$new_width = $thumb_width;
$new_height = $height / ($width / $thumb_width);
}
$thumb = imagecreatetruecolor( $thumb_width, $thumb_height );
imagecopyresampled($thumb,
$image,
0 - ($new_width - $thumb_width) / 2, // Center the image horizontally
0 - ($new_height - $thumb_height) / 2, // Center the image vertically
0, 0,
$new_width, $new_height,
$width, $height);
if($file_with_ext=="jpg"){ imagejpeg($thumb, $filename, 100); }
if($file_with_ext=="png"){ imagepng($thumb, $filename, 9); }
if($file_with_ext=="gif"){ imagegif($thumb, $filename, 9); }
unlink('thumb/'.$_FILES['imagelink']['name']);
}

php mysql database connection oops


First you have create connection.php :

host,$this->username,$this->password);

 

if(!$conn)// testing the connection
{
die ("Cannot connect to the database");
}

else
{

$this->myconn = $conn;

echo “Connection established”;

}

return $this->myconn;

}

function selectDatabase() // selecting the database.
{
mysql_select_db($this->database); //use php inbuild functions for select database

if(mysql_error()) // if error occured display the error message
{

echo “Cannot find the database “.$this->database;

}
echo “Database selected..”;
}

function closeConnection() // close the connection
{
mysql_close($this->myconn);

echo “Connection closed”;
}

}

?>

then this page include on another page :


connectToDatabase(); // connected to the database

echo "
"; // putting a html break

$connection->selectDatabase();// closed connection

echo ”
“;

$connection->closeConnection();
?>

MySQL Table Prefix Changer


prefix

Description

This script makes it possible for you to change table prefix for MySql databases.

Features

  • Add prefix to unprefixed tables
  • Rename/change prefix
  • Remove prefix

This is a quick modification of another script found at the below address.
http://www.nilpo.com/2009/01/web-development/mysql-table-prefix-changer-tool/.

Download

CLICK TO DOWNLOAD

how to create dynamic widget in wordpress


your wp theme go to functions.php put given below this code :

register_sidebar(array(
'name' => 'Home Post Boxes',
'id' => 'home-post-boxes',
'description' => 'The home post boxes widget area',
'before_widget' => '',
'after_widget' => '',
'before_title' => '',
'after_title' => ''
));

Then, applied this code on your page :

if(!dynamic_sidebar('home-post-boxes')) { $theme->hook('home-post-boxes'); }