Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add apply Image Convolution #33

Open
GoodLittleDev opened this issue Feb 3, 2014 · 0 comments
Open

add apply Image Convolution #33

GoodLittleDev opened this issue Feb 3, 2014 · 0 comments

Comments

@GoodLittleDev
Copy link

I wrote this to add Image Convolution matrix options to an image though I would share.
add this to \PHPImageWorkshop\Core\ImageWorkshopLayer.php

I put it just after apply Filter function.

public function applyImageConvolution($matrix, $div=0, $offset=0,$recursive=false){
if(is_string($matrix)){
$matrix = strtolower($matrix);
switch($matrix){
case "blur":
$matrix = array(array(1,1,1), array(1,.25,1), array(1,1,1));
$div = 8.25;
$offset = 0;
break;

            case "emboss": 
                $matrix = array(array(2, 2, 2), array(2, 1, -2), array(-2, -2, -2));
                $div = 0;
                $offset = 127;
            break;

            case  "gaussian blur" :
                $matrix = array(array(1.0, 2.0, 1.0), array(2.0, 4.0, 2.0), array(1.0, 2.0, 1.0));
                $div = 16;
                $offset = 0;
            break;

            case "sharpen" :
                $Matrix = array(array(-1.2, -1.2, -1.2),array(-1.2, .4, -1.2),array(-1.2, -1.2, -1.2)); 
                $div = array_sum(array_map('array_sum', $Matrix));  
                $offset = 0;
            break;

        }

    }
    if(is_array($matrix)){
        imageconvolution($this->image, $matrix, $div, $offset);
    }

    if ($recursive) {

        $layers = $this->layers;

        foreach($layers as $layerId => $layer) {
            $this->layers[$layerId]->applyImageConvolution($matrix, $div, $offset);
        }
    }



}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant