PHP Classes

File: mods/removewatermark.php

Recommend this page to a friend!
  Classes of Tony Bogdanov   PIMG   mods/removewatermark.php   Download  
File: mods/removewatermark.php
Role: Class source
Content type: text/plain
Description: User module: Watermark Remover
Class: PIMG
Process images using multiple operations
Author: By
Last change: 1.1
Date: 14 years ago
Size: 2,790 bytes
 

Contents

Class file image Download
<?php
/*
    PIMG USER MODULE
    Athor: ton4y@abv.bg
    Year: 2010
    Status: private (only the author can change it)
    Description:
        This module allows you to remove a watermark or any other rectangular part of an image
        by stretching it's corners together. You must specify the x and y start points and the
        width, and height of the selection to be removed. By default the rectangle will be
        removed and the left and right as well as the top and the bottom sides (1px thick,
        inline) will be stretched and fused together.
*/
class pimg_mod_removewatermark
{
   
/* Resources */
   
private $pimg;
   
   
// PIMG constructor
   
function __construct($pimg)
    {
       
$this -> pimg = $pimg;
    }
   
   
   
   
/*
        Removes the watermark
        @param: $x - x of start point
        @param: $y - y of start point
        @param: $width - selection width
        @param: $height - selection height
        @result: a pointer to the caller pimg class for furthur usage
    */
   
function init($x, $y, $width, $height)
    {
       
/* INPUT VALIDATORS */
       
if ($x < 0)
        {
           
$this -> pimg -> setDebug('X start point must be > 0', 'notice', __CLASS__);
           
$x = 0;
        }
        if (
$y < 0) {
           
$this -> pimg -> setDebug('Y start point must be > 0', 'notice', __CLASS__);
           
$y = 0;
        }
        if (
$x + $width > $this -> pimg -> width()) {
           
$this -> pimg -> setDebug('X end point (x + width) must be <= than image\'s width', 'notice', __CLASS__);
           
$width = $this -> pimg -> width();
        }
        if (
$y + $height > $this -> pimg -> height()) {
           
$this -> pimg -> setDebug('Y end point (y + height) must be <= than image\'s height', 'notice', __CLASS__);
           
$height = $this -> pimg -> height();
        }
       
       
// Scan inline
       
$top = $this -> pimg -> scan($x, $y, $width, 1);
       
$right = $this -> pimg -> scan($x + $width, $y, 1, $height);
       
$bottom = $this -> pimg -> scan($x, $y + $height, $width, 1);
       
$left = $this -> pimg -> scan($x, $y, 1, $height);
       
       
// Draw pixels
       
for($i = $x; $i < $x + $width; $i++)
            for(
$j = $y; $j < $y + $height; $j++)
               
$this
                   
-> pimg
                   
-> pixel($i, $j,
                       
$this
                           
-> pimg
                           
-> color()
                            ->
mix(array(
                                array(
                                   
$this
                                       
-> pimg
                                       
-> color()
                                        ->
mix(array(
                                            array(
$top[$i - $x][0] -> color(), 100 - ($j - $y) / $height * 100),
                                            array(
$bottom[$i - $x][0] -> color(), ($j - $y) / $height * 100)
                                        )),
50),
                                array(
                                   
$this
                                       
-> pimg
                                       
-> color()
                                        ->
mix(array(
                                            array(
$left[0][$j - $y] -> color(), 100 - ($i - $x) / $width * 100),
                                            array(
$right[0][$j - $y] -> color(), ($i - $x) / $width * 100)
                                        )),
50)
                            ))
                    ) ->
draw($this -> pimg);
       
       
// PIMG callback
       
return $this -> pimg;
    }
}
?>