Jump to content

Recommended Posts

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?

 

post-169006-0-24107300-1400897241_thumb.png

Edited by cerulean

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);

post-3105-0-85988400-1400913439_thumb.png

post-3105-0-73726400-1400913455_thumb.png

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.