cerulean Posted May 24, 2014 Share Posted May 24, 2014 (edited) I have a black and white image dividing a city into zip codes. So a bunch of shapes and that's it. I load it (imagecreatefrompng) and I'm filling the zipcodes with color based on coordinates of a spot in the zipcode and a color relevant to information about it. If I use imagefill (or imagefilltoborder) to fill a zip code it works great. But - I also need to apply text and lines to that image on top of those filled shapes. My problem is it's always doing the fill last no matter what order I put it in the code - so anywhere a line crosses a zipcode it only gets half filled in. For example I attached an image - if i turn off the lines the white box is filled in with a shade of red. Not a great example since I think the line is right on top of the coordinate of the fill but it does it all over the image. What am I missing? Is there not a way to choose the order your draw to the image object? Is there a way to apply a change before doign the next one short of writing and reloading the file? Edited May 24, 2014 by cerulean Quote Link to comment https://forums.phpfreaks.com/topic/288729-php-gd-applying-image-changes-in-order-not-working-imagefill-wont-fill/ Share on other sites More sharing options...
requinix Posted May 24, 2014 Share Posted May 24, 2014 Can you post the code? And maybe a sample image you're processing? Quote Link to comment https://forums.phpfreaks.com/topic/288729-php-gd-applying-image-changes-in-order-not-working-imagefill-wont-fill/#findComment-1480678 Share on other sites More sharing options...
Barand Posted May 24, 2014 Share Posted May 24, 2014 These two samples draw a square within an outer square. A fill is applied from just inside the top left corner of each square. gd1 - the fills are applied then the lines are added gd2 - the lines are added before the fills are applied. Not surprisingly, events occur in the order they are coded gd1.php <?php $im = imagecreate(200,200); $bg = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $bk = imagecolorallocate($im, 0, 0, 0); $rd = imagecolorallocate($im, 0xCC, 0, 0); $bl = imagecolorallocate($im, 0, 0, 0xCC); imagerectangle($im, 0, 0, 199, 199, $bk); imagesetthickness($im, 2); imagerectangle($im, 50, 50, 150, 150, $bk); // add fills imagefill($im, 2, 2, $rd); imagefill($im, 52, 52, $bl); // add lines imageline($im, 100, 0, 100, 199, $bk); imageline($im, 0, 100, 199, 100, $bk); // output header("Content-type: image/png"); imagepng($im); imagedestroy($im); gd2.php <?php $im = imagecreate(200,200); $bg = imagecolorallocate($im, 0xFF, 0xFF, 0xFF); $bk = imagecolorallocate($im, 0, 0, 0); $rd = imagecolorallocate($im, 0xCC, 0, 0); $bl = imagecolorallocate($im, 0, 0, 0xCC); imagerectangle($im, 0, 0, 199, 199, $bk); imagesetthickness($im, 2); imagerectangle($im, 50, 50, 150, 150, $bk); // add lines imageline($im, 100, 0, 100, 199, $bk); imageline($im, 0, 100, 199, 100, $bk); // add fills imagefill($im, 2, 2, $rd); imagefill($im, 52, 52, $bl); // output header("Content-type: image/png"); imagepng($im); imagedestroy($im); Quote Link to comment https://forums.phpfreaks.com/topic/288729-php-gd-applying-image-changes-in-order-not-working-imagefill-wont-fill/#findComment-1480682 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.