Page 1 of 1

[ASK] Convert Color/Black to White

Posted: 2014-10-14T22:13:20-07:00
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.

Re: [ASK] Convert Color/Black to White

Posted: 2014-10-14T22:23:54-07:00
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

Re: [ASK] Convert Color/Black to White

Posted: 2014-10-15T01:21:45-07:00
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

Re: [ASK] Convert Color/Black to White

Posted: 2014-10-15T01:50:44-07:00
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