[ASK] Convert Color/Black to White

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
farros
Posts: 3
Joined: 2014-10-14T21:29:43-07:00
Authentication code: 6789

[ASK] Convert Color/Black to White

Post by farros »

Dear Expert,

I am newbie in Imagick. Kindly need your help what code in php for convert Color/Black symbol to white?
I tried to use below;

Code: Select all

convert donut_black.png -edge 1 -negate   donut_white.png


but still in the border.

I want convert donut_black.png :
Image
to
Image

Thanks
Nug.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: [ASK] Convert Color/Black to White

Post by fmw42 »

Your background image needs to be made white or whatever color you want to use so that the alpha channel will show that color.

Code: Select all

convert donut_black.png -alpha off -fill white -colorize 100 -alpha on donut_white.png
To see what is going on, extract the alpha channel and the background image using

Code: Select all

convert donut_black.png -alpha off donut_black_background.png
convert donut_black.png -alpha extract donut_black_alpha.png
see
http://www.imagemagick.org/Usage/masking/#alpha
farros
Posts: 3
Joined: 2014-10-14T21:29:43-07:00
Authentication code: 6789

Re: [ASK] Convert Color/Black to White

Post by farros »

fmw42 wrote:Your background image needs to be made white or whatever color you want to use so that the alpha channel will show that color.

Code: Select all

convert donut_black.png -alpha off -fill white -colorize 100 -alpha on donut_white.png
To see what is going on, extract the alpha channel and the background image using

Code: Select all

convert donut_black.png -alpha off donut_black_background.png
convert donut_black.png -alpha extract donut_black_alpha.png
see
http://www.imagemagick.org/Usage/masking/#alpha
Please see http://www.docsbiz.com/png.php . The result is white blank.

Code: Select all

$pngDirectory = "uploadspng/"; #Directory where donut_black.png
$pagenameblack = 'donut_black.png';
$pagenamewhite = 'donut_white.png';
$pngWithPathBlack = $pngDirectory.$pagenameblack;
$pngWithPathWhite = $pngDirectory.$pagenamewhite;
 
   
    exec("convert $pngWithPathBlack -alpha off -fill white -colorize 100 -alpha on $pngWithPathWhite");

    echo '<div class="notibar msgsuccess"><a class="close"></a><p>Picture of <font color="red">'.$pagenamewhite.'</font> success to be converted</p></div>';
    echo "<p><a href=\"$pngWithPathWhite\"><img src=\"$pngWithPathWhite\" alt=\"\" /></a></p>";
Need your advice,

Thanks
farros
Posts: 3
Joined: 2014-10-14T21:29:43-07:00
Authentication code: 6789

Re: [ASK] Convert Color/Black to White

Post by farros »

Solved with this code

Code: Select all

<?php
$date = date_create();
//echo date_format($date, 'U') . "\n";
 
$pngDirectory = "uploadspng/"; #Directory where donut_black.png
$pagenameblack = 'donut_black.png';
$pagenamewhite = date_format($date, 'U').'_donut_white.png';
$pngWithPathBlack = $pngDirectory.$pagenameblack;
$pngWithPathWhite = $pngDirectory.$pagenamewhite;
 
   
    exec("convert $pngWithPathBlack -edge 1 -negate $pngWithPathWhite");

    echo '<div class="notibar msgsuccess"><a class="close"></a><p>Picture of <font color="red">'.$pagenamewhite.'</font> success to be converted</p></div>';
    echo '<p><a href="'.$pngWithPathWhite.'"><img src="http://www.docsbiz.com/'.$pngWithPathWhite.'" alt="" /></a></p>';
   
 
?>
Thanks All
Post Reply