Results 1 to 10 of 17
-
29th Nov 2009, 01:52 PM #1OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.com[PHP] imageBox V1 (Text,Rotate,Watermak,Resize)
Heya all, Ive created a Image Editing class to help you edit pictures via PHP
Some of the features include
- Add Text (Add strings of text on the image)
- Rotate Image (Rotate the image with degrees such as 180 and 75 Degrees)
- Watermarking (Simply add a water wark by telling the class what watermark file to use)
- Resize (Scale down an image to any Dimenstions)
- Output to browser (Send your image and all your changes to the browser)
- Output to file (Using the saveAs method you can easily export your changed images to your server)
Heres some examples
Resize to browser
PHP Code:<?php
include 'imageBox.class.php';
$Image = new imageBox("path/to/file.png");
$Image->resize(640,480)->toBrowser();
?>
PHP Code:<?php
include 'imageBox.class.php';
$Image = new imageBox("path/to/file.png");
$Image->resize(640,480)->rotate(75)->toBrowser();
?>
PHP Code:<?php
include 'imageBox.class.php';
$Image = new imageBox("path/to/file.png");
$Image->resize(640,480)->rotate(75)->saveAs("save/as/image.png");
//Note: you change the extention when saving
//$Image->resize(640,480)->rotate(75)->saveAs("save/as/image.gif");
//$Image->resize(640,480)->rotate(75)->saveAs("save/as/image.jpg");
?>
PHP Code:<?php
include 'imageBox.class.php';
$Image = new imageBox("path/to/file.png");
$Image
->resize(320,320)
->text("Hello World!","FFF",10,40,40)
->watermark("images/myWatermark.png","br")
->saveAs(dirname(__FILE__).'/images/the_file.png',75)
->toBrowser('jpg',100);
//This is saving the file and then outputting it to the browser
//Note: when saving as jpg you can set the 2nd parameter for quality 0-100%
?>
PHP Code:<?php
class imageBox{
/*Private*/
private $mainFile,$mainImage,$mainInfo;
/*
*** Constructor (Takes a local filename)
*/
function __construct($file){
$this->mainFile = $file;
//Check to see if file exists
if(!file_exists($this->mainFile)){
trigger_error("Image does not exists (".basename($this->mainFile).")",E_USER_ERROR);
}
//Other wise lets gather some info
$this->mainInfo = $this->_gatherFileInfo($this->mainFile);
//Now we have to create a new image object
$this->mainImage = $this->_createNewImage($this->mainFile);
}
/*
* Public
* Note: All public methods should return $this unless there output methods / final methods
**/
public function text($text,$color = '000000',$size = 5,$x = 0, $y = 0){
$rgb = $this->html2rgb($color);
imagestring($this->mainImage, $size, $x, $y, $text, imagecolorallocate($this->mainImage,$rgb[0],$rgb[1],$rgb[2]));
//Return the context
return $this;
}
public function rotate($degree, $color = 'FFFFFF'){
//Get hex for colour code
$rgb = $this->html2rgb($color);
//Chgeck the degree is in range
$degree = (($degree > 0 && $degree < 360) ? $degree : 180);
//rotate the image accordingly
$this->mainImage = imagerotate($this->mainImage,$degree,imagecolorallocate($this->mainImage,$rgb[0],$rgb[1],$rgb[2]));
//Update the mainImage Dx
$this->mainInfo->width = imagesx($this->mainImage);
$this->mainInfo->height = imagesy($this->mainImage);
//Return the context
return $this;
}
public function watermark($file,$position = 'bottomright'){
( /*Check and create watermark from file*/
file_exists($file)
? $this->watermark = $this->_createNewImage($file)
: trigger_error("imageBox:: Unable to open watermark file (".basename($file).")",E_USER_ERROR)
);
//Get watermark sizes
$this->watermark_info = $this->_gatherFileInfo($file);
//Set the hieghts
//Lets get the posstion of the where we want to place the watermark
switch($position){
case 'topleft':case 'tl':
$this->watermark_pos_x = 3;
$this->watermark_pos_y = 3;
break;
case 'topright':case 'tr':
$this->watermark_pos_x = ($this->mainInfo->width - $this->watermark_info->width)-3;
$this->watermark_pos_y = 3;
break;
case 'bottomleft':case 'bl':
$this->watermark_pos_x = -3;
$this->watermark_pos_y = ($this->mainInfo->height - $this->watermark_info->height)-3;
break;
case 'bottomright':case 'br':
$this->watermark_pos_x = ($this->mainInfo->width - $this->watermark_info->width)-3;
$this->watermark_pos_y = ($this->mainInfo->height - $this->watermark_info->height)-3;
break;
default:
$this->watermark_pos_x = 0;
$this->watermark_pos_y = ($this->mainInfo->height - $this->watermark_info->height)-3;
break;
}
//Add the watermarked image to the mainImage
imagecopy(
$this->mainImage,
$this->watermark,
$this->watermark_pos_x,
$this->watermark_pos_y,
0,0,
$this->watermark_info->width,
$this->watermark_info->height
);
imagedestroy($this->watermark);
//Return the context
return $this;
}
public function resize($width = 640,$height = 480){
//Setup scale
$scale = min(
$width/$this->mainInfo->width,
$height/$this->mainInfo->height
);
if ($scale == 1){
return $this; // no need to change
}
$new_width = ($this->mainInfo->width * $scale);
$new_height = ($this->mainInfo->height * $scale);
$xpos = (($width - $new_width) / 2);
$ypos = (($height - $new_height) / 2);
//Create a copy of the current image for changeover
$this->imageBackup = $this->mainImage;
//Make new image with the Dx passed
$this->mainImage = imagecreatetruecolor($new_width,$new_height);
//Create plain background
$this->plain_bg = imagecolorallocate($this->mainImage,255,255,255);
//Add the plain Background
imagefilledrectangle($this->mainImage,0,0,$width,$height,$this->plain_bg);
//Copy the main image to the newly sized image
imagecopyresampled(
$this->mainImage,$this->imageBackup,0,0,0,0,$new_width,$new_height,
$this->mainInfo->width,$this->mainInfo->height
);
//Delete the old image
imagedestroy($this->imageBackup);
//Update the Dx for the mainImage
$this->info->width = $width;
$this->info->height = $height;
//Return the main object for streamlining
return $this;
}
public function toBrowser($outputType = 'jpg',$quality = 100){
//Send the file to browser and EXIT
switch($outputType){
case "gif":
header('Content-type: image/gif');
imagegif($this->mainImage,NULL);
exit;
break;
case "png":
header('Content-type: image/png');
imagepng($this->mainImage,NULL);
break;
case "jpg":case "jpeg":
header('Content-type: image/jpeg');
imagejpeg($this->mainImage,NULL, (int)$quality);
exit;
break;
default:
trigger_error("imageBox:: Unaable to output to browser, check output ext (".$outputType.")",E_USER_ERROR);
break;
}
}
public function saveAs($location,$quality = 100){
$info = pathinfo($location);
$extension = $info['extension'];
switch($extension){
case "gif":
imagegif($this->mainImage, $location);
break;
case "png":
imagepng($this->mainImage, $location);
break;
case "jpg":case "jpeg":
imagejpeg($this->mainImage, $location, $quality);
break;
default:
trigger_error("imageBox:: Unaable to save image, check save ext (".$extension.")",E_USER_ERROR);
break;
}
return $this;
}
/*Private Functions*/
private function _createNewImage($file){
$info = $this->_gatherFileInfo($file);
switch($info->mime){
case "image/gif":
return imagecreatefromgif($file);
break;
case "image/png":
return imagecreatefrompng($file);
break;
case "image/jpg":
case "image/jpeg":
return imagecreatefromjpeg($file);
break;
default:
trigger_error("imageBox:: Unable to load image into GD, Incorrect mime type (".$info->mime.")",E_USER_ERROR);
break;
}
}
private function _gatherFileInfo($file){
$info = getimagesize($file);
$this->tmp_info = new stdClass();
/*Send the info to the stdClass*/
$this->tmp_info->width = $info[0];
$this->tmp_info->height = $info[1];
$this->tmp_info->bits = $info['bits'];
$this->tmp_info->mime = $info['mime'];
return $this->tmp_info;
}
private function html2rgb($color) {
if ($color[0] == '#'){$color = substr($color, 1);}
if(strlen($color) == 6){
list($r, $g, $b) = array($color[0].$color[1],$color[2].$color[3],$color[4].$color[5]);
}elseif(strlen($color) == 3){
list($r, $g, $b) = array($color[0].$color[0],$color[1].$color[1],$color[2].$color[2]);
}else{
return array(hexdec("FF"),hexdec("FF"),hexdec("FF"));
}
return array(hexdec($r),hexdec($g),hexdec($b));
}
/*Destructor to remove the image*/
function __destruct(){
imagedestroy($this->mainImage);
}
}
?>litewarez Reviewed by litewarez on . [PHP] imageBox V1 (Text,Rotate,Watermak,Resize) Heya all, Ive created a Image Editing class to help you edit pictures via PHP Some of the features include Add Text (Add strings of text on the image) Rotate Image (Rotate the image with degrees such as 180 and 75 Degrees) Watermarking (Simply add a water wark by telling the class what watermark file to use) Resize (Scale down an image to any Dimenstions) Output to browser (Send your image and all your changes to the browser) Output to file (Using the saveAs method you can easily Rating: 5Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
29th Nov 2009, 02:02 PM #2Too busy :|Website's:
L337Fx.com BeastieBay.net
-
29th Nov 2009, 02:19 PM #3Respected Developer
Haven't tested it but the code itself looks clean and structured. Good job
.
-
29th Nov 2009, 02:21 PM #4OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comthanks
if anyone needs anymore features let me know,, see what i can do.... i had to take a whole maths course to be able to handle fucking dimensions
not easy shit mane
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
29th Nov 2009, 02:46 PM #5Member
could pls add a crop function with bottom to top cropping.
example. a video screen cap contain the filename size etc on top portion on the screen cap. so we will crop from bottom to top that , we will get the image without those video descriptions
-
29th Nov 2009, 02:48 PM #6OPMemberWebsite's:
litewarez.net litewarez.com triniwarez.comnp lemme try
Join Litewarez.net today and become apart of the community.
Unique | Clean | Advanced (All with you in mind)
Downloads | Webmasters
Notifications,Forum,Chat,Community all at Litewarez Webmasters
-
29th Nov 2009, 03:39 PM #7Member
Thank you
Coding Horror Fan
I don't read PM's frequently .
-
29th Nov 2009, 04:42 PM #8Member
lite you ever consider making a website for all your coding/classes. It would be a big success
-
29th Nov 2009, 04:45 PM #9
-
29th Nov 2009, 04:49 PM #10Too busy :|Website's:
L337Fx.com BeastieBay.net
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
.htaccess - rotate image url?
By AlternativeWeb in forum Web Development AreaReplies: 8Last Post: 30th May 2012, 12:16 PM -
Rotate banner in Blogspot??
By arnav in forum Web Development AreaReplies: 7Last Post: 2nd May 2012, 01:30 AM -
Ads exchange and auto rotate
By nICEsHARE in forum Webmaster DiscussionReplies: 0Last Post: 16th Dec 2011, 06:26 AM -
How to rotate multi Images like Trump card effect
By torrfriend in forum Technical Help Desk SupportReplies: 6Last Post: 15th Nov 2011, 07:08 AM -
php resize
By Chris2k in forum Web Development AreaReplies: 11Last Post: 14th Jul 2011, 02:37 PM
themaCreator - create posts from...
Version 3.45 released. Open older version (or...