Category: Technology
November 6th, 2008
b2evolution Plugin
Published on November 6th, 2008 @ 04:11:25 pm , using 385 words, 85 views
I haven't written anything in my 'scripts' category yet, but I've really wanted to, so here it is ![]()
This blog is built on the open source b2evolution blog system. It's simple to use and very customizable. One thing I noticed it was lacking was the functionality to resize photos when their uploaded so that people don't have 3mb files that stretch way beyond the limits of the screen and take forever to load.
I searched for a plugin that would do it, but I found nothing, although it's something that people are asking for. I wrote a PHP script that can resize during upload, but I had no idea how to plug the functionality into my b2evo.
I spent a lot of time struggling to figure it out. Then I found a plugin called 'Quick Upload' (http://forums.b2evolution.net/viewtopic.php?t=15569). I installed it and it worked great for uploading files, but still didn't resize them. Since this script was much easier for me to read, I (along with the b2evo forums' help) was able to add the functionality for resizing.
So here's the download for those who might want it: Quick Upload with Loko Modification
If you already have the 'Quick Upload' plugin, just add this code to 'upload_window.php' around line 489 (right after "// Store File object into DB: $newFile->dbsave();"):
//LOKO RESIZE MOD **********************
$ext = strtolower(substr( $newFile->dget('name'), strrpos($newFile->dget('name'), '.') + 1 )); //get extension
$fullpath = $newFile->get_full_path(); //get fullpath+filename
list($width,$height)=getimagesize($fullpath); //get width & height
if ($width > 799 or $height > 799) { //make sure w>799 & h>799
if ($ext == "jpg" or $ext == "gif" or $ext == "png") {
if ($ext == "jpg") { $src = imagecreatefromjpeg($fullpath); }
else if ($ext == "gif") { $src = imagecreatefromgif($fullpath); }
else if ($ext == "png") { $src = imagecreatefrompng($fullpath); }
//create new dimensions
if ($width > $height) {
$newwidth=800;
$newheight=($height/$width)*800;
} else {
$newheight=800;
$newwidth=($width/$height)*800;
}
$tmp=imagecreatetruecolor($newwidth,$newheight);
//resize
imagecopyresampled( $tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height );
//set quality
if ($ext == "jpg") { imagejpeg($tmp,$fullpath,100); }
else if ($ext == "gif") { imagegif($tmp,$fullpath,100); }
else if ($ext == "png") { imagepng($tmp,$fullpath,9); }
//delete temporary images
imagedestroy($src);
imagedestroy($tmp);
}
}
//EOF LOKO MOD *************************
And for all you people who have no idea what I'm talking about and read this anyway, you should have stopped at 'open source' ![]()
