Location: PHPKode > scripts > Screenshot > screenshot/manipulation.class.php
<?php

/**
 * manipulate
 * 
 * @package Screenshot
 * @author Danltn
 * @copyright 2008
 * @license GPL
 * @version 0.1 Beta
 * @access public
 */
class manipulate extends screenshot
{
  /**
   * manipulate::__construct()
   * 
   * @param bool $pump
   * @param bool $height
   * @param bool $width
   * @return
   */
    public function __construct( $pump = false, $height = false, $width = false )
    {
        parent::__construct( $pump, $height, $width );
    }

  /**
   * manipulate::crop()
   * 
   * @param integer $x
   * @param integer $y
   * @param integer $width
   * @param integer $height
   * @return object $this
   */
    public function crop( $x = 10, $y = 100, $width = 400, $height = 400 )
    {
        $temp = imagecreate( $width, $height );
        imagecopy( $temp, $this->image, 0, 0, $x, $y, $width, $height );
        $this->image = $temp;
        return $this;
    }

  /**
   * manipulate::border()
   * 
   * @param integer $px
   * @param array $colour
   * @return object $this
   */
    public function border( $px = 5, $colour = array('255', '255', '255') )
    {
        $img_width = $this->_getImageWidth() + ( 2 * $px );
        $img_height = $this->_getImageHeight() + ( 2 * $px );
        $temp = imagecreate( $img_width, $img_height );
        $border = imagecolorallocate( $temp, $colour[0], $colour[1], $colour[2] );
        if ( !is_array($colour) ) {
            $border = imagecolorallocatealpha( $temp, 0, 0, 0, 127 );
        }
        else {
            $border = imagecolorallocate( $temp, ($colour[0]) ? $colour[0] : 0, ($colour[1]) ? $colour[1] : 0, ($colour[2]) ? $colour[2] : 0 );
        }
        imagefilledrectangle( $temp, 0, 0, $img_width, $img_height, $border );
        imagecopy( $temp, $this->image, $px, $px, 0, 0, $this->_getImageWidth(), $this->_getImageHeight() );
        $this->image = $temp;
        return $this;
    }

    /**
     * manipulate::resize()
     *
     * @param int $percent
     * @return $this
     */
    public function resize( $percent = 50 )
    {
        $percent = $percent / 100;
        $width = $this->_getImageWidth();
        $height = $this->_getImageHeight();
        $new_width = $width * $percent;
        $new_height = $height * $percent;
        $temp = imagecreatetruecolor( $new_width, $new_height );
        imagecopyresampled( $temp, $this->image, 0, 0, 0, 0, $new_width, $new_height, $width, $height );
        $this->image = $temp;
        unset($temp);
        return $this;
    }

  /**
   * manipulate::rotate()
   * 
   * @param integer $angle
   * @param integer $bg_colour
   * @return object $this
   */
    public function rotate( $angle = 90, $bg_colour = 0 )
    {
        $this->image = imagerotate( $this->image, $angle, $bg_colour, 0 );
        return $this;
    }

  /**
   * manipulate::_getImageWidth()
   * 
   * @return int $width
   */
    private function _getImageWidth()
    {
        return ( int )imagesx( $this->image );
    }

  /**
   * manipulate::_getImageHeight()
   * 
   * @return int $height
   */
    private function _getImageHeight()
    {
        return ( int )imagesy( $this->image );
    }
}

?>
Return current item: Screenshot