Greenriver Posted January 31, 2011 Share Posted January 31, 2011 Hi, I'm trying to invert a random section of an image. The only way I've thought of doing this in PHP, is to split the image up into sections using imagecopyresampled then negate one of the sections using the imagefilter IMG_FILTER_NEGATE. Then put them all back together using imagecopymerge. Now I have managed to get this working when negating the first section ($split_first), but whenever I try to negate any other section (e.g. $split_sec) nothing happens. Now I know my code doesn't randomly invert it, I'm just trying to get it to work for each section first then I'll try get that working. Below I have posted my code. Any help would be be appreciated, Thank you in advance! <?php $image=imagecreate(400, 100); $red = imagecolorallocate($image, 255, 0, 0); imagefill($image, 0, 0, $red); $split_first=imagecreate(100, 100); $split_sec=imagecreate(100, 100); $split_thir=imagecreate(100, 100); $split_four=imagecreate(100, 100); imagecopyresampled($split_first,$image,0,0,0, 0,100,100,100,100); imagecopyresampled($split_sec,$image,100,0,100,0,100,100,100,100); imagecopyresampled($split_thir,$image,200,0,200,0,100,100,100,100); imagecopyresampled($split_four,$image,300,0,300,0,100,100,100,100); imagefilter($split_sec, IMG_FILTER_NEGATE); imagecopymerge($image,$split_first,0,0,0,0,100,100,100); imagecopymerge($image,$split_sec,100,0,100,0,0,100,100); imagecopymerge($image,$split_thir,200,0,200,0,0,100,100); imagecopymerge($image,$split_thir,300,0,300,0,0,100,100); imagepng($image); imagedestroy($image); header('Content-Type: image/png'); echo $image; ?> Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 31, 2011 Share Posted January 31, 2011 Just a crazy idea... 1. create 2 png from original 2. negate png 1 3. make 3/4 of png 1 transparent 4. copy png 1 onto png 2 Quote Link to comment Share on other sites More sharing options...
Greenriver Posted January 31, 2011 Author Share Posted January 31, 2011 Hi, Thank you for the help. The problem is that the image is not going to be plain colour like the one above (I'm just testing to get it working first) the image will be an actual photo and all of the image will need to be negated at one point, so that would mean I couldn't overwrite the second half with the first like in your idea. Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 31, 2011 Share Posted January 31, 2011 Perhaps like this? (I took original, cropped upper left 1/4, saved it, negated it, overlaid it back on original) http://www.nstoia.com/sat/crop/xxx.php Quote Link to comment Share on other sites More sharing options...
Greenriver Posted January 31, 2011 Author Share Posted January 31, 2011 Hi there, Yes that's it, I think that is currently what my code does above, but it only can do the first section, and no others. Does that negate any section of the image? As I can't seem to fathom it to negate every section of the image. Quote Link to comment Share on other sites More sharing options...
litebearer Posted January 31, 2011 Share Posted January 31, 2011 easy enough to make it do what you want. are you going to negate each section the same? Quote Link to comment Share on other sites More sharing options...
Greenriver Posted January 31, 2011 Author Share Posted January 31, 2011 Hi there, Yeah so the idea is I have an image which is 400 x 100. I split it up into four sections each 100 x 100. Then select a section at random to negate. Thus far I've only been able to negate the first section, so the other three sections I can't get to negate. Thank you for your help! Quote Link to comment Share on other sites More sharing options...
Greenriver Posted February 1, 2011 Author Share Posted February 1, 2011 So what would I need to change in my code to make it so $split_sec, $split_thir and $split_four can be inverted aswell? Quote Link to comment 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.