After the follow code:
$im = new \Imagick('fu.png');
$im->thresholdimage(0.9, 127);
I'm getting this image:
so I need to close the open areas. When I copy the code from http://phpimagick.com/Imagick/morphology?morphologyType=9 which is:
$im = new \Imagick('fu.png');
$im->thresholdimage(0.9, 127);
$canvas = $this->getCharacterOutline();
$kernel = \ImagickKernel::fromBuiltIn(\Imagick::KERNEL_DISK, "6");
$canvas->morphology(\Imagick::MORPHOLOGY_CLOSE, 1, $kernel);
header("Content-Type: image/png");
echo $im->getImageBlob();
I'm getting error: PHP Fatal error: Using $this when not in object context in..
I don't have ANY idea how to use this, I've never seen anything like it and I'm sure it's not a matter of logical thinking but knowing exactly how the hell to do that or you're f***ed.
Please help!
UPDATE:
As Roljhon explained I need to use the getchar.. function so I did:
private function getCharacterOutline()
{
$im = new \Imagick('fu.png');
$im->thresholdimage(0.9, 127);
$character = new \Imagick();
$character->newPseudoImage(
$im->getImageWidth(),
$im->getImageHeight(),
"canvas:white"
);
$canvas = new \Imagick();
$canvas->newPseudoImage(
$im->getImageWidth(),
$im->getImageHeight(),
"canvas:black"
);
$character->compositeimage(
$im,
\Imagick::COMPOSITE_COPYOPACITY,
0, 0
);
$canvas->compositeimage(
$character,
\Imagick::COMPOSITE_ATOP,
0, 0
);
$canvas->setFormat('png');
return $canvas;
}
$canvas = $this->getCharacterOutline();
$kernel = \ImagickKernel::fromBuiltIn(\Imagick::KERNEL_DISK, "6");
$canvas->morphology(\Imagick::MORPHOLOGY_CLOSE, 1, $kernel);
header("Content-Type: image/png");
echo $im->getImageBlob();
I don't know what I'm doing and what this piece of crap supposed to do anyway... I'm getting error ofc...