Watermark.php
<?php

    class Watermark{

        var $logo = "";
        var $picture = "";
        var $x = 5;
        var $y = 5;

        function Watermark( $picture , $logo , $align = "TOP_LEFT" ){
            $this->setPicture( $picture );
            $this->setLogo( $logo );
            $this->setAlign( $align );
            $this->insertWatermark( $align );

        }
        function setPicture( $picture ) {
            $this->picture = imagecreatefromjpeg ( $picture );
        }
        function getPicture(){
            return $this->picture;
        }
        function setLogo( $logo ){
            $this->logo = imagecreatefrompng( $logo );
        }
        function getLogo(){
            return $this->logo;
        }
        function getX(){
            return $this->x;
        }
        function getY(){
            return $this->y;
        }
        function setAlign( $align ) {

            if ( $align == "TOP_LEFT" ){

                $this->x = 5;
                $this->y = 5;

            }else if ( $align == "TOP_CENTER" ) {

                $x1 = imagesx( $this->getPicture() ) / 2;
                $x2 = imagesx( $this->getLogo() ) / 2;
                $this->x = $x1 - $x2;
                $this->y = 5;

            }else if ( $align == "TOP_RIGHT" ) {

                $this->x = imagesx( $this->getPicture() ) -
                    ( imagesx( $this->getLogo() ) + 5 );
                $this->y = 5;

            }else if ( $align == "BOTTOM_LEFT" ) {

                $this->x = 5;
                $this->y = imagesy( $this->getPicture() ) -
                    ( imagesy( $this->getLogo() ) + 5 );

            }else if ( $align == "BOTTOM_CENTER" ) {

                $x1 = imagesx( $this->getPicture() ) / 2;
                $x2 = imagesx( $this->getLogo() ) / 2;
                $this->x = $x1 - $x2;
                $this->y = imagesy( $this->getPicture() ) -
                    ( imagesy( $this->getLogo() ) + 5 );

            }else if ( $align == "BOTTOM_RIGHT" ) {

                $this->y = imagesy( $this->getPicture() ) -
                    ( imagesy( $this->getLogo() ) + 5 );
                $this->x = imagesx( $this->getPicture() ) -
                    ( imagesx( $this->getLogo() ) + 5 );

            }else{

                $this->y = 5;
                $this->x = 5;

            }

        }

        function insertWatermark ( $align ){

            $this->setAlign ( $align );
            $x = imagesx ( $this->getLogo() );
            $y = imagesy ( $this->getLogo() );
            imagecopy( $this->getPicture() , $this->getLogo() ,
                $this->getX() , $this->getY() , 0 , 0 , $x , $y );

        }

        function display(){
            imagejpeg( $this->getPicture() , 'temp.jpg' );
            print "<img src='temp.jpg' border='0' >";
        }






    }

?>
 
Hosted by www.Geocities.ws

1