FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Help with PHP BD imaging functionality
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Help with PHP BD imaging functionality [message #182488 is a reply to message #182484] Thu, 08 August 2013 12:55 Go to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 8/7/2013 7:53 PM, Ed Jay wrote:
> I'm trying to highlight a portion of a grayscale image, with the
> highlighting color applied to pixels within a range of level only. I'm not
> getting the result I seek.
>
> While the grayscale values within the range possibly yield the highlight
> color, the entire image is masked with the color from the last
> imagecolorallocate.
>
> My code follows, and the 'Process of interest' is the offending culprit.
>
> How do I highlight the value-region of interest with the background of my
> choosing?
>
> $source_image = $_GET['source'];
> $threshold = $_GET['threshold'];
> $range = $_GET['range'];
>
> $starting_img = imagecreatefromjpeg($source_image);
> $img_data = getimagesize($source_image);
> $width = $img_data[0];
> $height = $img_data[1];
> $final = imagecreatetruecolor($img_data[0],$img_data[1]);
>
> $gray_threshold = 1*$threshold;
> $gray_range = 1*$range;
> $gray_top = ($gray_threshold + $gray_range);
> if ($gray_top > 255) {$gray_top = 255;}
> $highlight_color = imagecolorallocate($final,0,0,255);
>
> //Process of interest:
>
> for($x=0; $x<$width; $x++){
> for($y=0; $y<$height; $y++){
>
> $gray =(imagecolorat($final,$x,$y) >> 16) & 0xFF;
> if (($gray > $gray_threshold) && ($gray < $gray_top)) {$gray =
> $highlight_color;}
> $gray2 = imagecolorallocate($final,$gray,$gray,$gray);
> imagesetpixel($final, $x,$y,$gray2);
>
> }
> }
>
> header('Content-Type: image/jpeg');
> imagejpeg($final);
> imagedestroy($starting_img);
> imagedestroy($final);
>
> Thanks in advance,
>

Hi, Ed,

I think I understand what you're trying to do, but haven't actually run
the code (I don't happen to have any gray scale jpegs handy right now).

I see you create the $starting_image. However, I don't see where you
use it again. You don't copy the image into $final, so after

$final = imagecreatetruecolor($img_data[0],$img_data[1]);

$final is black.

I also don't see

Perhaps

$gray =(imagecolorat($final,$x,$y) >> 16) & 0xFF;

should be using $starting_image instead of $final?

Alternatively, why are you creating $final? Why not operate on
$starting_image directly?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: GUI designer in html
Next Topic: Dictionary Words
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 09 12:25:36 GMT 2024

Total time taken to generate the page: 0.05279 seconds