Resizing All Images in Directory
May0
I need a script for resize all images in one directory. I have create thumbnails for a site. I have not so much time write these code. I found two different code and mixed them. I love PHP, it is very easy to solve problem with little scripts. If you resize in same directory it will be resize resized images. If you need in same directory, just resized for temp directory and move it to your real one.
<?
/*
* Class: SimpleImage, Author: Simon Jarvis, Copyright: 2006 Simon Jarvis, Date: 08/11/06
* Link: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
* See the GNU General Public License for more details: http://www.gnu.org/licenses/gpl.html
*/
class SimpleImage {
var $image;
var $image_type;
function load($filename) {
$image_info = getimagesize($filename);
$this->image_type = $image_info[2];
if( $this->image_type == IMAGETYPE_JPEG ) {
$this->image = imagecreatefromjpeg($filename);
} elseif( $this->image_type == IMAGETYPE_GIF ) {
$this->image = imagecreatefromgif($filename);
} elseif( $this->image_type == IMAGETYPE_PNG ) {
$this->image = imagecreatefrompng($filename);
}
}
function save($filename, $image_type=IMAGETYPE_JPEG, $compression=75, $permissions=null) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image,$filename,$compression);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image,$filename);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image,$filename);
}
if( $permissions != null) {
chmod($filename,$permissions);
}
}
function output($image_type=IMAGETYPE_JPEG) {
if( $image_type == IMAGETYPE_JPEG ) {
imagejpeg($this->image);
} elseif( $image_type == IMAGETYPE_GIF ) {
imagegif($this->image);
} elseif( $image_type == IMAGETYPE_PNG ) {
imagepng($this->image);
}
}
function getWidth() {
return imagesx($this->image);
}
function getHeight() {
return imagesy($this->image);
}
function resizeToHeight($height) {
$ratio = $height / $this->getHeight();
$width = $this->getWidth() * $ratio;
$this->resize($width,$height);
}
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);
}
function scale($scale) {
$width = $this->getWidth() * $scale/100;
$height = $this->getheight() * $scale/100;
$this->resize($width,$height);
}
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image;
}
}
// End of SimpleImage class
/* Directory Listing
Source : http://www.spoono.com/php/tutorials/tutorial.php?id=10
*/
// Define the path as relative
$path = "/home/site/public_html/images/";
// Using the opendir function
$dir_handle = @opendir($path) or die("ERROR: Cannot open <b>$path</b>");
echo("Directory Listing of $path<br/>");
//running the while loop
while ($file = readdir($dir_handle))
{
if($file != "." && $file != "..")
{
$image = new SimpleImage();
$image->load("images/".$file);
$image->resize(80,60);
$image->save("images2/mini_".$file);
echo("• $file <br>");
}
}
//closing the directory
closedir($dir_handle);
?>
Google Create New Programming Language : GO
Nov0
Google Engineers create new programming language “Go”. In first look it is look like C++ or Java. We will see, how it will be.
More details :
http://www.golang.me/google-launches-its-own-programming-language-go/
Turn Off Autocomplete Form in Internet Explorer
Nov1
A webmastersucks user ask me “The only problem is that IE will store the MD5 ] password when it “saves” the password. Have you been able to overcome that?”. Solution is really simple, just we can use autocomplete attribute in form tag. It will be close autocomplete in form. It will better in password protected sites.
<form name="form" method="post" autocomplete="off">....</form>
Grouping Date with Datetime in MySQL
Nov0
This is very basic and very useful command for mysql. I need user registration date by date. Firstly, i calculate with PHP, after i think it must be a basic way. I found this mysql command. I hope you’ll enjoy.
SELECT DATE_FORMAT(registerdate, '%Y-%m-%d') AS dd, COUNT(id) as TotalUser FROM UserTable GROUP BY dd;
Unique Email Address in Mysql
Oct0
I have a big mail database but there are some dublicate email addresses. I need unique email address lists and i follow this way;
Firstly i create temporary table for unique email address
CREATE TABLE mail_temp ( `email` varchar( 255 ) NOT NULL default '' ) ENGINE = MyISAM;
After i add unique email address to that temp table
INSERT INTO mail_temp SELECT DISTINCT(email) FROM mail_table
I dropped my real email table
DROP TABLE mail_table;
After all, i create new mail table and moved the temporary mail table to in.
CREATE TABLE mail_table( `email` varchar( 255 ) NOT NULL default '' ) ENGINE = MyISAM; INSERT INTO mail_table SELECT DISTINCT(email) FROM mail_temp; DROP TABLE mail_temp;
Select Users Age in MySQL
Oct0
Advertising agencies wants to user profile for advertisements. I need my users age. I found a little solution. I write this SQL statement for select which year my users born and group them.
SELECT count(id) AS total,YEAR(birthday) AS birth_year FROM users GROUP BY YEAR(birthday);
BBPress is Forum of WordPress
Sep3
I create a new web site about “The Martial Arts” with Wordpress. I want to create a forum work with WordPress together. I remember WordPress team works on forum software. They called “BBPress“. I install BBPress and it is asked me some WordPress questions about config file, i set them and i have got forum integrated with WordPress. Users are same in forum and WordPress. I suggest you BBPress if you are using Wordpress and want basic forum. BBPress is better in SEO. It is always come with its own seo system like wordpress. Here is my forum >
Read Config File to install BB Press
define('AUTH_KEY', 'aaaaa');
define('SECURE_AUTH_KEY', 'bbbbb');
define('LOGGED_IN_KEY', 'ccccc');
define('NONCE_KEY', 'ddddd');
FCK Editor is Reloaded: CK Editor
Sep0
I always use FCK Editor in my php codes, it is really helpful for coding. 10 days ago FCK Editor is reloaded and change its name to CK Editor. There is lots of changing.
New Version of FCK Editor (CK Editor 3.0)
- Working on Chrome clearly
- It’s faster and faster
- Better user interface
- New javascript API
- Work with php, asp, asp.net,Coldfusion

