The command is:
convert i.png -bordercolor white -border 1x1 -matte -fill none -fuzz 20% -draw "matte 0,0 'floodfill'" -shave 1x1 o.png
I use imagemagick by php_imagick.dll. I want use the command in php,but i can't run 'exec' or 'passthru'.
so what I write like this...
$image = new Imagick('i.png');
//what code???
$image->writeImage('o.png');
thanks a lot.
how to use this command in php?
Re: how to use this command in php?
thanks,but i found nothing about how to remove background from image.
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: how to use this command in php?
I have no way to test this (I haven't installed Imagick and don't use PHP) but I think the code will look something like this:
Pete
Code: Select all
$image = new Imagick('i.png');
// -bordercolor white -border 1x1
// note that $border is also used later in the floodfill operation
$border=new ImagickPixel();
$border->setColor("white");
$image->borderImage($border,1,1);
// -matte
$image->setImageMatte(TRUE);
// -fill none
$fill=new ImagickPixel();
$fill->setColor("none");
$image->setFillColor($fill);
// -fuzz 20% -draw "matte 0,0 'floodfill'"
$draw = new ImagickDraw();
// I don't know if 20% is passed as 20 or .2 - try both
// see http://ca3.php.net/manual/en/function.imagick-mattefloodfillimage.php
$draw->matteFloodfillImage(0.0,20,$border,0,0);
// Now draw the $draw object on to $image
$image->drawImage($draw);
// -shave 1x1
$image->shaveImage(1,1);
$image->writeImage('o.png');
$draw->destroy();
$border->destroy();
$fill->destroy();
Re: how to use this command in php?
Thanks el_supremo.
I tested it. but it can't work.
setFillColor is the ImagickDraw class function, so $image->setFillColor($fill) can't run,
and matteFloodfillImage is the Imagick class function, so $draw->matteFloodfillImage(0.0,20,$border,0,0) can't run.
How to fix it?
I change $image->setFillColor into $draw->setFillColor, but it can't work too...
I tested it. but it can't work.
setFillColor is the ImagickDraw class function, so $image->setFillColor($fill) can't run,
and matteFloodfillImage is the Imagick class function, so $draw->matteFloodfillImage(0.0,20,$border,0,0) can't run.
How to fix it?
I change $image->setFillColor into $draw->setFillColor, but it can't work too...
-
- Posts: 1015
- Joined: 2005-03-21T21:16:57-07:00
Re: how to use this command in php?
Give this a try:
I can't find a way to set a fuzz value for a draw operation so I've removed the draw operations and tried to implement the command by using only Imagick and ImagickPixel methods. I'm afraid I don't know enough about Imagick to get any further with this so if this doesn't work I'm out of ideas.
Pete
Code: Select all
$image = new Imagick('i.png');
// -bordercolor white -border 1x1
// note that $border is also used later in the floodfill operation
$border = new ImagickPixel();
$border->setColor("white");
$image->borderImage($border,1,1);
// -matte
$image->setImageMatte(TRUE);
// -fill none -fuzz 20% -draw "matte 0,0 'floodfill'"
// I don't know if 20% is passed as 20 or .2 - try both
// see http://ca3.php.net/manual/en/function.imagick-mattefloodfillimage.php
$image->matteFloodfillImage(0.0,20,$border,0,0);
// -shave 1x1
$image->shaveImage(1,1);
$image->writeImage('o.png');
Pete
Re: how to use this command in php?
It's run, but the image has no change......
Thank you very much.
Thank you very much.