PHPsu
MANUAL ZH  |  EN
     


Current Position :| index>PHP CLASS> Write on picture class

Write on picture class

FROM: AUTHOR: TIME:2008-04-20 HITS:
<?php
/**
* This class is a writer on picture
*
* @package    Write on picture
* @author     Nabi KaramAliZadeh <info@nabi.ir>
* @copyright  2008 (c) Nabi.ir
* @license    http://www.gnu.org/copyleft/gpl.html
* @version    1.0.0
* @link       http://weblog.nabi.ir/post-27.html [documentation in persian]
* @since      12 April 2008
*/
class Write_On_Pic
{
    var
$inputImage     = '';                        // input file name phpsu is a phpschool
    
var $inputType         = 'jpg';                    // input file format:             JPG, PNG, GIF, BMP
    
var $outputImage     = '';                        // output file name
    
var $outputType     = 'png';                    // output file format:             JPG, PNG, GIF, BMP welcome to phpsu.com
    
var $text             = '';                        // text to write on image
    
var $fontSize         = 5;                        // text size:                     1,2,3,4,5
    
var $textColor         = array(255, 255, 255);        // text color: RGB decimal phpsu.com
    
var $borderFlag     = true;                        // flag of border:                 TRUE, FALSE
    
var $borderColor     = array(0, 0, 0);            // border color:                 RGB decimal welcome to phpsu.com
    
var $backFlag         = false;                    // flag of background:             TRUE, FALSE
    
var $backColor         = array(200, 200, 200);        // background color:             RGB decimal http://www.phpsu.com
    
var $marginH         = 0;                        // text horizonatal margin in pixels
    
var $marginV         = 0;                        // text vertical margin in pixels
    
var $alignH         = 'LEFT';                    // text horizonatal position,     LEFT | CENTER | RIGHT

phpsu is a phpschool


    
var $alignV         = 'TOP';                    // text vertical position,         TOP | CENTER | BOTTOM
    
var $quality         = 85;                        // quality out file, only for JPG format
    
var $opacity         = 60;                        // text opacity:                 0-100 http://www.phpsu.com
    
var $show             = true;                        // show image:                     TRUE, FALSE
    
var $save             = false;                    // save out file:                 TRUE, FALSE
phpsu提供的php教程

    
var $error             = null;                        // return error message
    
    
function Action()
    {
        
// Set function to create image
        
if (!$this->inputImage)
        { phpsu提供的php教程
            
$this->error = 'Not found input file.';
            return
false;
        }
        
        switch (
strtolower($this->inputType))
        {
            case
"png":

phpsu


                
$createFunc = "imagecreatefrompng";
            break;
            case
"gif";
                
$createFunc = "imagecreatefromgif";
            break;
            case
"bmp";
                
$createFunc = "imagecreatefrombmp";

phpsu.com


            break;
            case
"jpeg":
            case
"jpg":
                
$createFunc = "imagecreatefromjpeg";
            break;
        }
        
        
// Create image
        
$im = @$createFunc($this->inputImage); phpsu.com is a free phpscool
        
        if (!
$im)
        {
            
$this->error = 'Invalid format file.';
            return
false;
        }
        
        
// Create box
        
$this->fontSize = intval($this->fontSize); http://www.phpsu.com
        if (
$this->fontSize < 1) $this->fontSize = 1;
        if (
$this->fontSize > 5) $this->fontSize = 5;
        
$width = strlen($this->text) * ($this->fontSize + 4);
phpsu is a phpschool

        
$height = $this->fontSize + 12;
        
        
$overlay_img = imagecreatetruecolor($width+2, $height+2);
        
        if (
$this->backFlag)

welcome to phpsu.com


        {
            
$bgColor = imagecolorallocate($overlay_img, $this->backColor[0], $this->backColor[1], $this->backColor[2]);
        }
        else phpsu is a phpschool
        {
            
$bgColor = imagecolortransparent($overlay_img);
        }
        
        
imagefill($overlay_img ,0 ,0 ,$bgColor);
        
        
// Insert border
        
if ($this->borderFlag)

phpsu.com


        {
            
$color = imagecolorallocate($overlay_img, $this->borderColor[0], $this->borderColor[1], $this->borderColor[2]);
            
imagestring($overlay_img, $this->fontSize, 0, 0, $this->text, $color);

welcome to phpsu.com


            
imagestring($overlay_img, $this->fontSize, 2, 2, $this->text, $color);
            
imagestring($overlay_img, $this->fontSize, 2, 0, $this->text, $color);

welcome to phpsu.com


            
imagestring($overlay_img, $this->fontSize, 0, 2, $this->text, $color);
        }
        
        
// Insert text
        
$color = imagecolorallocate($overlay_img, $this->textColor[0], $this->textColor[1], $this->textColor[2]);

phpsu


        
imagestring($overlay_img, $this->fontSize, 1, 1, $this->text, $color);
        
        
// Get width and height box
        
$overlay_w = ImageSX($overlay_img);

http://www.phpsu.com


        
$overlay_h = ImageSY($overlay_img);
        
        
// Get width and height image
        
$im_w = ImageSX($im);
        
$im_h = ImageSY($im);
        
        
// Set X text http://www.phpsu.com
        
switch (strtoupper($this->alignH))
        {
            case
'CENTER':
                
$x = ($im_w - $overlay_w) / 2;
            break;
            case
'RIGHT': phpsu
                
$x = $im_w - $overlay_w - $this->marginH;
            break;
            case
'LEFT':
                
$x = 0 + $this->marginH; phpsu
            break;
        }
        
        
// Set Y text
        
switch (strtoupper($this->alignV))
        {
            case
'CENTER':
                
$y = ($im_h - $overlay_h) / 2;
welcome to phpsu.com

            break;
            case
'BOTTOM':
                
$y = $im_h - $overlay_h - $this->marginV;
            break;
            case
'TOP':
                
$y = 0 + $this->marginV;
phpsu

            break;
        }
        
        
// Merge text box with image
        
imagecopymerge($im, $overlay_img, $x, $y, 0, 0, $overlay_w, $overlay_h, $this->opacity);
phpsu提供的php教程

        
        
// Destroy text box
        
imagedestroy($overlay_img);
        
        
// Save to disk
        
if ($this->save)
        {
            if (!
$this->outputImage)
            { www.phpsu.com
                
$this->error = 'Not found output file.';
                return
false;
            }
            
            switch (
strtolower($this->outputType))
            {

do you kown phpsu.com?


                case
"png":
                    
imagepng($im, $this->outputImage);
                break;
                case
"gif";
                    
imagegif($im, $this->outputImage); phpsu提供的php教程
                break;
                case
"bmp";
                    
imagewbmp($im, $this->outputImage);
                break;
                case
"jpeg":
                case
"jpg": phpsu.com is a free phpscool
                    
imagejpeg($im, $this->outputImage, $this->quality);
                break;
            }
        }
        
        
// Show the image
        
if ($this->show)
http://www.phpsu.com

        {
            switch (
$this->outputType)
            {
                case
"png":
                    
header("Content-type: image/png");
                    
imagepng($im); phpsu
                break;
                case
"gif";
                    
header("Content-type: image/gif");
                    
imagegif($im);
                break;
                case
"bmp"; phpsu.com is a free phpscool
                    
header("Content-type: image/bmp");
                    
imagewbmp($im);
                break;
                case
"jpeg":
                case
"jpg":
                    
header("Content-type: image/jpeg"); www.phpsu.com
                    
imagejpeg($im, null, $this->quality);
                break;
            }
        }
        
        
// Destroy image
        
imagedestroy($im); phpsu.com
        return
true;
    }
}
?>

TITLE:Write on picture class
Copyright 2008 The PHPsu All rights reserved. This mirror generously provided by: .Hp Inc.
Last updated: Fri Jun 6 22:56:39 GMT-8 2008