Page 1 of 1

how to use this command in php?

Posted: 2008-08-07T18:28:18-07:00
by sptx
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.

Re: how to use this command in php?

Posted: 2008-08-09T03:04:26-07:00
by Bonzo
Try looking on this site and you may find an example you can use:

http://valokuva.org/?cat=1.

Re: how to use this command in php?

Posted: 2008-08-11T02:41:33-07:00
by sptx
thanks,but i found nothing about how to remove background from image. :(

Re: how to use this command in php?

Posted: 2008-08-11T12:35:28-07:00
by el_supremo
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:

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();
Pete

Re: how to use this command in php?

Posted: 2008-08-11T18:53:52-07:00
by sptx
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... :?

Re: how to use this command in php?

Posted: 2008-08-11T20:11:46-07:00
by el_supremo
Give this a try:

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');
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

Re: how to use this command in php?

Posted: 2008-08-12T17:49:54-07:00
by sptx
It's run, but the image has no change...... :(
Thank you very much. :D