Background Removal command

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
marzmurphy

Background Removal command

Post by marzmurphy »

Hi all,

Im desperatly trying to find a solution to removing the colour black from an image(the backfround is black with a white object in front) . I have tried image masking but no succses. Im currently using the -transparent command...and was hoping if someone could have a quick look at the code to see where im going wrong...(no image is been displayed)

<?php
// If the form has been submitted do this
if ( $Submit ) {

// Temporary upload image name
$original_image = $_FILES['all.jpg']['all.jpg'];


// Name to save the image as - in this case the same as the original
$new_image = $_FILES['all.jpg']['all.jpg'];

//command to remove the background
$cmd = " $filename -transparent black ";
// $new_Iimage is the output_filename
exec(" convert $cmd $new_image ");");

echo "File uploaded<br>";

echo "<img src=\"".$new_image."\">";
}
else { ?>
<p>File to upload:</p>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
<input type="file" name="filename" />
<input type="Submit" name="Submit" value="Submit" />
</form>
<?php } ?>

Any suggestions where im going wrong...id really appreciate any help..so thanks to anyone who might know and can help!!!

Kind Rgrds,

Mary
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Background Removal command

Post by Bonzo »

You have a problem here:

Code: Select all

$new_image = $_FILES['all.jpg']['all.jpg'];
Try echoing some of your variables to confirm they contain what you expect.

You will probably still have a black background anyway as jpg does not support transparancy.
Post Reply