loganbest Posted December 20, 2007 Share Posted December 20, 2007 Is there a way in PHP to take three grayscale images (red channel, green channel, and blue channel) and combine them like photoshop does to create an RGB colour image? I know there has to be a way with GD Library's powerful backend. Quote Link to comment https://forums.phpfreaks.com/topic/82474-solved-image-functions/ Share on other sites More sharing options...
littledragon Posted December 20, 2007 Share Posted December 20, 2007 Not unless you make one, mate :-) can be done, you need to combine the hex value of each pixel in each file one by one. Googled it? Quote Link to comment https://forums.phpfreaks.com/topic/82474-solved-image-functions/#findComment-419398 Share on other sites More sharing options...
loganbest Posted December 20, 2007 Author Share Posted December 20, 2007 I'm not sure how to do that. Quote Link to comment https://forums.phpfreaks.com/topic/82474-solved-image-functions/#findComment-419656 Share on other sites More sharing options...
MadTechie Posted December 20, 2007 Share Posted December 20, 2007 Googled it? I'm not sure how to do that. Erm... back to the books then (or the freelance section) Quote Link to comment https://forums.phpfreaks.com/topic/82474-solved-image-functions/#findComment-419659 Share on other sites More sharing options...
loganbest Posted December 20, 2007 Author Share Posted December 20, 2007 so you don't know what the other guy is talking about doing it pixel by pixel? Quote Link to comment https://forums.phpfreaks.com/topic/82474-solved-image-functions/#findComment-419666 Share on other sites More sharing options...
MadTechie Posted December 20, 2007 Share Posted December 20, 2007 yes do i know, but this is for helping with current script problems not a site for getting scription written for you.. But Heres a starting block.. this will convert color to grayscale..its not great needs a few improvments (as the quality drops if used over and over) but it works.. you should be able to alter this to suite your needs <?php function convert($filename) { $filename = imagecreatefromjpeg($filename); list($width, $height) = getimagesize($filename); $bwimage= imagecreate($width, $height); for ($c=0;$c<256;$c++) { $palette[$c] = imagecolorallocate($bwimage,$c,$c,$c); } //Reads the origonal colors pixel by pixel for ($y=0;$y<$height;$y++) { for ($x=0;$x<$width;$x++) { $rgb = imagecolorat($source,$x,$y); $r = ($rgb >> 16) & 0xFF; $g = ($rgb >> & 0xFF; $b = $rgb & 0xFF; //This is where we actually use yiq to modify our rbg values, //and then convert them to grayscale palette $gs = $this->yiq($r,$g,$b); imagesetpixel($bwimage,$x,$y,$palette[$gs]); } } // Outputs a jpg image, but you can change this to png or gif if that is what you are working with imagejpeg($bwimage, $filename); imagedestroy($bwimage); } ?> hope this helps Quote Link to comment https://forums.phpfreaks.com/topic/82474-solved-image-functions/#findComment-419693 Share on other sites More sharing options...
Barand Posted December 20, 2007 Share Posted December 20, 2007 or you could just use imagefilter ($image, IMG_FILTER_GRAYSCALE); Quote Link to comment https://forums.phpfreaks.com/topic/82474-solved-image-functions/#findComment-419895 Share on other sites More sharing options...
loganbest Posted December 21, 2007 Author Share Posted December 21, 2007 I got it working with Imagemagick Quote Link to comment https://forums.phpfreaks.com/topic/82474-solved-image-functions/#findComment-420253 Share on other sites More sharing options...
MadTechie Posted December 23, 2007 Share Posted December 23, 2007 or you could just use imagefilter ($image, IMG_FILTER_GRAYSCALE); True, but the code above is old (php 4 version) imagefilter came out in php5 Quote Link to comment https://forums.phpfreaks.com/topic/82474-solved-image-functions/#findComment-421461 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.