Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #10441
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Newsgroups | comp.lang.php |
| Subject | Re: Help with PHP BD imaging functionality |
| Date | 2013-08-08 08:55 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <ku04ff$oo$1@dont-email.me> (permalink) |
| References | <odn509dlaemf7vs2oik9bqi38a42vdvu9n@4ax.com> |
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@attglobal.net
==================
Back to comp.lang.php | Previous | Next — Previous in thread | Find similar | Unroll thread
Help with PHP BD imaging functionality Ed Jay <edMbj@aes-intl.com> - 2013-08-07 16:53 -0700
Re: Help with PHP BD imaging functionality The Natural Philosopher <tnp@invalid.invalid> - 2013-08-08 08:58 +0100
Re: Help with PHP BD imaging functionality Ed Jay <edMbj@aes-intl.com> - 2013-08-08 05:01 -0700
Re: Help with PHP BD imaging functionality The Natural Philosopher <tnp@invalid.invalid> - 2013-08-08 14:12 +0100
Re: Help with PHP BD imaging functionality Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-09 01:13 +0200
Re: Help with PHP BD imaging functionality Jerry Stuckle <jstucklex@attglobal.net> - 2013-08-08 08:55 -0400
csiph-web