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 #182489 is a reply to message #182487] Thu, 08 August 2013 13:12 Go to previous messageGo to previous message
The Natural Philosoph is currently offline  The Natural Philosoph
Messages: 993
Registered: September 2010
Karma:
Senior Member
On 08/08/13 13:01, Ed Jay wrote:
> The Natural Philosopher wrote:
>
>> is the problem less that you don't know how to make GD do what you
>> want, then you don't actually know how to do what you want at all?
> A massive sprinkling of each...
>> Is what you want covered by this?
> I already considered it a possibility, but it intuitively didn't strike me
> as the best method available. Is it the only method available to
> accomplish my goal?

I am still unclear as to what your goal actually is?
Beyond that you have an image that you want to partially modify.

"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 am simply not clear as to what you MEAN by 'highlighting' or 'highlighting color' or 'range of level'
Are you essentially trying to slap a layer of virtual translucent ink over an area of a monochrome image?

so eg. blacker bits or whiter bits turn a 'whiter shade of pale'?


>> http://www.php.net/manual/en/image.examples.merged-watermark.php
>>
>>> //Process of interest:
>>>
>>> for($x=0; $x<$width; $x++){
>>> for($y=0; $y<$height; $y++){
>>>
>>> $gray =(imagecolorat($final,$x,$y) >> 16) & 0xFF;
That line at least is not extracting a gray value from an RGB pixmap.
Its extracting the red value component.
you need to extract R G and B separately - they SHOULD be the same, and
average them unless your are sure they image is truly monochrome.

eg
|$rgb = imagecolorat($im, 10, 15);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;|

$gray=$r+$b+$g)/3;

>>> if (($gray > $gray_threshold) && ($gray < $gray_top)) {$gray =
>>> $highlight_color;}
well that's weird. $highlight_colour is presumably not gray?
And not an R,G or B value either.
Its an index into a table..of RGB values.
>>> $gray2 = imagecolorallocate($final,$gray,$gray,$gray);
So this ^^^^ is a rubbish line
>>> imagesetpixel($final, $x,$y,$gray2);
And that wont do what you want either.
All you had to do was

imagesetpixel($final, $x,$y,$highlight_color);


As I understand it, the magical typecasting and loose typing of PHP has as usual made things harder, not easier.

The way GD works is that you allocate a color to a table of colors using RGB[alpha] values,. but the output of imagecolorallocate is not a 'color' in RGB terms, its a pointer to an _array_ of RGB[alpha] values! Worse still it only applies to a given IMAGE.


see http://www.php.net/manual/en/function.imagecolorsforindex.php

What that means is that if you e.g. want to apply any given arbitrary color value to an image, you need 2GB table color values!!!

>>> }
>>> }
>>>

I am not going to test it, but this is something like what I *THINK* you
need
Assuming the original image is actually monochrome, and you have used
imagecolorallocate($final, $r,$g,$b) to set up $higlight_color, and
$grey_threshold, and $grey_top are actually numbers set between 0 and 255..

for($x=0; $x<$width; $x++)
{
for($y=0; $y<$height; $y++)
{
$gray =(imagecolorat($final,$x,$y) & 0xFF); // why not use blue instead?
if (($gray > $gray_threshold) && ($gray < $gray_top)) // pixel in defined gresay scale range
imagesetpixel($final, $x,$y,$highlight_color); // simply set it to highlight color.

}
}
However this won't actually result in a translucent highlighting, it will simply be 'for a range of greyscale, replace with a single solid color'

One of the reasons I don't actually like GD that much is that easy things are made quite hard... and hard things are made almost impossible.

Which is why I use C and pngwriter to write graphs when its more than a simple task.

e.g. http://pngwriter.sourceforge.net/manual-en.php
---------------------------------------------------

*Plot Blend*

Plots the colour given by red, green blue, but blended with the existing
pixel value at that position. opacity is a double that goes from 0.0 to
1.0. For example, 0.0 will not change the pixel at all, and 1.0 will
plot the given colour.Anything in between will be a blend of both pixel
levels. *Please note*: This is neither alpha channel nor PNG
transparency chunk support. This merely blends the plotted pixels.

void plot_blend(int x, int y, double opacity, int red, int green, int blue);

void plot_blend(int x, int y, double opacity,double red, double green,
double blue);

------------------------------------------------------------------

which allows you to 'tint' a relevant pixel with a directly specified color.

And also direct access to RGB values of any pixel. In both directions.

GS's 'cleverness' in avoiding have to send RGB and alpha values every time, and makes it impossible to do so without 'allocating a color' to the image for every conscievable hue you need, makes it pants for difficult stuff.

I haven't ever looked at Imagick, beyond a moments heartstopping when I looked at all the stuff it did that I really didnt need.And ghow much I would need to learn to avoid using it.

so will pass comment on that.

Sigh.

--
Ineptocracy

(in-ep-toc’-ra-cy) – a system of government where the least capable to lead are elected by the least capable of producing, and where the members of society least likely to sustain themselves or succeed, are rewarded with goods and services paid for by the confiscated wealth of a diminishing number of producers.
[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: Fri Nov 22 17:20:00 GMT 2024

Total time taken to generate the page: 0.04790 seconds