purefusion Posted March 7, 2006 Share Posted March 7, 2006 Hey, I'm building a 'build-a-label' type system in PHP using GD2/ImageMagick type functions. What I'm looking for is a function (preferably in GD2, since I'm used to those functions) that would convert a (colored) logo to black and white, and/or a (colored or black and white) logo to a monochromatic specified color, such as red or blue. I appreciate all help on this so much!Thanks :) Quote Link to comment https://forums.phpfreaks.com/topic/4366-gd2-converting-and-uploaded-graphic-to-black-and-white-and-monochrome/ Share on other sites More sharing options...
purefusion Posted March 8, 2006 Author Share Posted March 8, 2006 I know Image Magick has the -monochrome function, is there anything like this in GD? What about a colorize function to convert black and white to color? Quote Link to comment https://forums.phpfreaks.com/topic/4366-gd2-converting-and-uploaded-graphic-to-black-and-white-and-monochrome/#findComment-15462 Share on other sites More sharing options...
Barand Posted March 8, 2006 Share Posted March 8, 2006 If image is gif or png (palletted) you can change the color inthe image's pallette. This example lets you click on an image and change the clicked color to that specified in the R,G,B fields (red by default)Save in "colorchange.php"[code]<?php$fn = $_GET['fn'];$x = $_GET['x'];$y = $_GET['y'];$r = $_GET['R'];$g = $_GET['G'];$b = $_GET['B'];$im = imagecreatefrompng($fn);$col = imagecolorat($im, $x, $y);imagecolorset($im, $col, $r, $g, $b);header("content-type: image/png");imagepng($im);imagedestroy($im);?>[/code]Save in test.php and run[code]<?php$fn = 'myimage.png'; // set to your image nameif (isset($_GET['pic_x'])) { $x = $_GET['pic_x']; $y = $_GET['pic_y']; $r = $_GET['R']; $g = $_GET['G']; $b = $_GET['B']; echo "<img src='colorchange.php?fn=$fn&x=$x&y=$y&R=$r&G=$g&B=$b'>";}?><FORM>Convert to R<INPUT TYPE='TEXT' name='R' value='255' size='3' maxlength='3'> G<INPUT TYPE='TEXT' name='G' value='0' size='3' maxlength='3'> B<INPUT TYPE='TEXT' name='B' value='0' size='3' maxlength='3'><BR><INPUT TYPE='IMAGE' name='pic' src='<?php echo $fn ?>'></FORM>[/code]hth Quote Link to comment https://forums.phpfreaks.com/topic/4366-gd2-converting-and-uploaded-graphic-to-black-and-white-and-monochrome/#findComment-15517 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.