473,805 Members | 1,958 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Grayscaling images causes mangled image + segfault

[php]
/**
* Class for grayscaling image
*
* @author Phil Powell
* @version 1.2.1
* @package IMAGE_CATALOG:: IMAGE
*/
class ImageGrayscaleG enerator extends ImageResizeComp onents {

/
*----------------------------------------------------------------------------------------------------------------------------------------------------------
This class exists due to the rather poor performance of the
imagecopymergeg ray() command
Borrowing code snippet from http://us3.php.net/manual/en/functio...ymergegray.php
first line comment
Will perform actual grayscaling of image one pixel at a time.
-----------------------------------------------------------------------------------------------------------------------------------------------------------
*/
// REMEMBER TO USE REFERENCE POINTER ONTO $image OBJECT TO ENSURE
"static" CHANGE TO OBJECT AND NOT TO INSTANCE

/**
* Constructor. Set all properties dynamically
*
* @access public
* @param resource $image (reference)
* @param resource $newImage (reference)
* @param int $image_width
* @param int $image_height
*/
function ImageGrayscaleG enerator(&$imag e, &$newImage, $image_width,
$image_height) { // CONSTRUCTOR
global $section;
foreach (array($section , 'newImage', "${section}_wid th", "$
{section}_heigh t") as $val) $this->$val =& ${$val};
}

/**
* Make the image grayscale
*
* @access protected
*/
function makeGray() { // VOID METHOD
global $section;
for ($i = 0; $i <= 255; $i++) $colorNDX[$i] =
@imagecolorallo cate($this->newImage, $i, $i, $i);

if (is_array($colo rNDX) && @sizeof($colorN DX) 0) {
for ($y = 0; $y < $this->{$section . '_height'}; $y++) {
for ($x = 0; $x < $this->{$section . '_width'}; $x++) {
$ndx = @imagecolorat($ this->image, $x, $y);
$ndxColorArray = @imagecolorsfor index($this->image, $ndx);
$avg = floor(($ndxColo rArray['red'] + $ndxColorArray['green'] +
$ndxColorArray['blue']) / 3);
@imagesetpixel( $this->newImage, $x, $y, $colorNDX[$avg]);
}
}
}
}
}

if ($this->isSuccessful && $image && $willGrayscale) { // GRAYSCALE
IMAGE
$igg =& new ImageGrayscaleG enerator($image , $newImage,
$image_width, $image_height);
$igg->makeGray();
$igg = null;
}
[/php]

Whenever I run this class to grayscale an image, I wind up with the
resulting image being horribly mangled to the point of its original
format completely irreparable, furthermore, I wind up with an Apache
segfault and having to reboot the server to correct the problem.

Um, why?

Phil

Apr 14 '07
49 1738
| | Probably works from home because no company will hire him. Can't say
as
| | I would blame them - I sure wouldn't!
| >
| hmmm, jerry...i WORK from home because no company will HIRE me? do you
see a
| problem there with your reasoning? you're funny; just in a kind of sad
way.
| >
| >
|
| I never said you did anything productive. If your posts here are any
| indication, you don't.

you said:

probably works from home b/c no company will hire me.

i said:

how is it that you say i *work* from home yet i am *not* employed?

you said:

i never said you did anything productive. (which is completely non-sequitur)

i think:

it's too late at night for you...at least that's the benefit of the doubt
i'll afford you.
Apr 19 '07 #41
Steve wrote:
| | Probably works from home because no company will hire him. Can't say
as
| | I would blame them - I sure wouldn't!
| >
| hmmm, jerry...i WORK from home because no company will HIRE me? do you
see a
| problem there with your reasoning? you're funny; just in a kind of sad
way.
| >
| >
|
| I never said you did anything productive. If your posts here are any
| indication, you don't.

you said:

probably works from home b/c no company will hire me.

i said:

how is it that you say i *work* from home yet i am *not* employed?

you said:

i never said you did anything productive. (which is completely non-sequitur)

i think:

it's too late at night for you...at least that's the benefit of the doubt
i'll afford you.

Even too stoopid to understand plain English. No wonder no one will
hire you.

Troll. And a stoopid one, also.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 19 '07 #42

"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:Pq******** *************** *******@comcast .com...
| Steve wrote:
| | | Probably works from home because no company will hire him. Can't
say
| as
| | | I would blame them - I sure wouldn't!
| | >
| | hmmm, jerry...i WORK from home because no company will HIRE me? do
you
| see a
| | problem there with your reasoning? you're funny; just in a kind of
sad
| way.
| | >
| | >
| |
| | I never said you did anything productive. If your posts here are any
| | indication, you don't.
| >
| you said:
| >
| probably works from home b/c no company will hire me.
| >
| i said:
| >
| how is it that you say i *work* from home yet i am *not* employed?
| >
| you said:
| >
| i never said you did anything productive. (which is completely
non-sequitur)
| >
| i think:
| >
| it's too late at night for you...at least that's the benefit of the
doubt
| i'll afford you.
| >
| >
|
| Even too stoopid to understand plain English. No wonder no one will
| hire you.

hey genious, the reference to *work* and *employment* is literal. your
firgurative relation to *productivity* is non-sequitur. hence, while you
show you understand english, you show a complete inability to apply it in
context. that's probably a deeper theme for you that spans many areas in
your life - from logic to programming to ...

further, you seem to think i'm not employed or unemployable because i call
shitty code 'shitty code' an am sometime abrupt in how i speak to some
people. christ, you really must have fallen asleep in your logic classes in
college - or did you even go?

i'm done with you, stucco.

*PLONK*
Apr 19 '07 #43
On Apr 19, 9:48 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Steve wrote:
| | Probably works from home because no company will hire him. Can't say
as
| | I would blame them - I sure wouldn't!
| >
| hmmm, jerry...i WORK from home because no company will HIRE me? do you
see a
| problem there with your reasoning? you're funny; just in a kind of sad
way.
| >
| >
|
| I never said you did anything productive. If your posts here are any
| indication, you don't.
you said:
probably works from home b/c no company will hire me.
i said:
how is it that you say i *work* from home yet i am *not* employed?
you said:
i never said you did anything productive. (which is completely non-sequitur)
i think:
it's too late at night for you...at least that's the benefit of the doubt
i'll afford you.

Even too stoopid to understand plain English. No wonder no one will
hire you.

Troll. And a stoopid one, also.
But incredibly entertaining. In a "I'm trying so hard to be Simon
Cowell but I'm just too unwittingly self-flaggelating" kind of way.
--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===

Apr 19 '07 #44
On Apr 18, 11:35 pm, Schraalhans Keukenmeester
<bitbuc...@inva lid.spamwrote:
Steve wrote:
"Michael Daly" <MichaelD...@fo o.barwrote in message
news:DN******** *************** *******@magma.c a...
| Steve wrote:
|
| i work from home
|
| since you can't deal with people face to face. That's why you hide
| behind your computer and insult everyone.
no. it just cuts down my daily commute. in fact, i am in such a stature that
i've flown around the world to meet and discuss/plan development projects
with the boards of directors, cios, and ceos of many global corporations of
which most of them you've probably heard...such as toyota, porche, bmw,
audi, carfax, bnsf, american airlines, morgan stanley...and some that you
probably haven't.
all i can say is that we both leave said meetings with smiles. must be good
raport during the course of many a golf game and fine meals. :)
say what you will. your intention to insult me (making you hypocritical)
only does so were i to perceive it true. i obviously have no experience that
would render your remark as anything other than flatly false.
| Instead of taking up your mother issues with everyone else, how about
| you do the mature thing and get a therapist.
the thing about the oportunists who join a feeding frenzy is that they come
bearing teeth. i think yours have been left in the small cup of water on
your bathroom sink.
| Civil behavior is a pretty basic skill you've yet to learn.
<chucklingyou obviously haven't read this entire thread. say, the third
post down where comp.lang.php (the op's handle) is actually the code's
author (phil). phil and his rubbish-for-code is what i was going on about.
might i have used different words rather than 'brain-dead' (reference to the
author) had i know phil == comp.lang.php? probably. too late for that given
his nym-shifting. would i call shitty code by another name? i dare not, dear
rose.
| Cheers!
lol.

May I recommend someone to you who probably _is_ at your currently
rather lonely level, where we, earthbound minions, can only look up to
and tell our children wonderful fairytale stories of?

Look up Alan Connor, if you haven't already bumped into him at the six
mile high Ole Boys Network. He _surely_ will understand fully what you
mean and how we all fail to see the immense talent and wisdom you exhume.

In case you need further directions, Alan's in the encyclopaedia of
utter bliss following the terms 'Troll', 'A-hole' and 'Pseudologica
Fantastica'. Why they are in that particular order no-one down here knows.

@ Phil: Although there may be some valid points to be made (and done so
by others) about the actual code you posted, and while I share the
curiousness about the performance of your custom solution compared to
the off-the-shelf alternative, please ignore the trash talk. It's
something that appearantly comes with usenet territory. It's been in
fashion with some for years now, and it will probably outlive us all,
but after a while it's easier living with this minor nuisance than with
a boil on your behind or mosquitoes in the bedroom at night.
And, of course, there's always that shred of hope we will all once see
the light and are allowed to join the ranks of those miscomprehended
superheroes ;-)

GL
Sh.
Thanx SH.. I'm just waiting for that future HR company to google/
keyword this thread when dear ol' Steve looks for a job.

Apr 19 '07 #45
| But incredibly entertaining. In a "I'm trying so hard to be Simon
| Cowell but I'm just too unwittingly self-flaggelating" kind of way.

who is simon cowell? you watch too much tv. explains a lot to me.
Apr 19 '07 #46
| Thanx SH.. I'm just waiting for that future HR company to google/
| keyword this thread when dear ol' Steve looks for a job.

you really are a clueless fuckwit!

exactly WHAT would they be searching/keywording for? and exactly HOW would
they know 'Steve' was the applicant in front of them? wait, lemme guess...on
your resume in bold at the top, it reads: COMP.LANG.PHP (like a dumbass).

get a fucking clue. even if they did (which is IMPOSSIBLE), they'd certainly
agree that your code is shit. they may want me to tone down what name i use
for said rose, but we'd wink everytime we used the substitute.

as it is, my fte has enjoyed having me as an employee for about seven years
now. my pte has as well in a consultant position...unde r which contract, i
am on retainer. that should suggest to you that i have a *very* good
relationship there since they pay me each month regardless of whether i work
for them during that time or not - they know that whenever i do and for
whatever it is they have me do, i get it done. i've been pte this way for
two years now. and, except for my first consulting gig, all my pte contracts
have been by reference.

all that should tell you something; that you are wrong. even more, that you
should revisit the initial advice i gave you before the name calling
started, since it may be that i actually do know what i'm talking about.

either way:

*PLONK*
Apr 19 '07 #47
Steve wrote:
"Jerry Stuckle" <js*******@attg lobal.netwrote in message
news:Pq******** *************** *******@comcast .com...
| Steve wrote:
| | | Probably works from home because no company will hire him. Can't
say
| as
| | | I would blame them - I sure wouldn't!
| | >
| | hmmm, jerry...i WORK from home because no company will HIRE me? do
you
| see a
| | problem there with your reasoning? you're funny; just in a kind of
sad
| way.
| | >
| | >
| |
| | I never said you did anything productive. If your posts here are any
| | indication, you don't.
| >
| you said:
| >
| probably works from home b/c no company will hire me.
| >
| i said:
| >
| how is it that you say i *work* from home yet i am *not* employed?
| >
| you said:
| >
| i never said you did anything productive. (which is completely
non-sequitur)
| >
| i think:
| >
| it's too late at night for you...at least that's the benefit of the
doubt
| i'll afford you.
| >
| >
|
| Even too stoopid to understand plain English. No wonder no one will
| hire you.

hey genious, the reference to *work* and *employment* is literal. your
firgurative relation to *productivity* is non-sequitur. hence, while you
show you understand english, you show a complete inability to apply it in
context. that's probably a deeper theme for you that spans many areas in
your life - from logic to programming to ...

further, you seem to think i'm not employed or unemployable because i call
shitty code 'shitty code' an am sometime abrupt in how i speak to some
people. christ, you really must have fallen asleep in your logic classes in
college - or did you even go?

i'm done with you, stucco.

*PLONK*

Total moron.

And I haven't been called that since third grade. But that's about your
level of intelligence.

<PLONK>

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 19 '07 #48
comp.lang.php wrote:
On Apr 18, 11:35 pm, Schraalhans Keukenmeester
<bitbuc...@inva lid.spamwrote:
>Steve wrote:
>>"Michael Daly" <MichaelD...@fo o.barwrote in message
news:DN****** *************** *********@magma .ca...
| Steve wrote:
|
| i work from home
|
| since you can't deal with people face to face. That's why you hide
| behind your computer and insult everyone.
no. it just cuts down my daily commute. in fact, i am in such a stature that
i've flown around the world to meet and discuss/plan development projects
with the boards of directors, cios, and ceos of many global corporations of
which most of them you've probably heard...such as toyota, porche, bmw,
audi, carfax, bnsf, american airlines, morgan stanley...and some that you
probably haven't.
all i can say is that we both leave said meetings with smiles. must be good
raport during the course of many a golf game and fine meals. :)
say what you will. your intention to insult me (making you hypocritical)
only does so were i to perceive it true. i obviously have no experience that
would render your remark as anything other than flatly false.
| Instead of taking up your mother issues with everyone else, how about
| you do the mature thing and get a therapist.
the thing about the oportunists who join a feeding frenzy is that they come
bearing teeth. i think yours have been left in the small cup of water on
your bathroom sink.
| Civil behavior is a pretty basic skill you've yet to learn.
<chucklingy ou obviously haven't read this entire thread. say, the third
post down where comp.lang.php (the op's handle) is actually the code's
author (phil). phil and his rubbish-for-code is what i was going on about.
might i have used different words rather than 'brain-dead' (reference to the
author) had i know phil == comp.lang.php? probably. too late for that given
his nym-shifting. would i call shitty code by another name? i dare not, dear
rose.
| Cheers!
lol.
May I recommend someone to you who probably _is_ at your currently
rather lonely level, where we, earthbound minions, can only look up to
and tell our children wonderful fairytale stories of?

Look up Alan Connor, if you haven't already bumped into him at the six
mile high Ole Boys Network. He _surely_ will understand fully what you
mean and how we all fail to see the immense talent and wisdom you exhume.

In case you need further directions, Alan's in the encyclopaedia of
utter bliss following the terms 'Troll', 'A-hole' and 'Pseudologica
Fantastica'. Why they are in that particular order no-one down here knows.

@ Phil: Although there may be some valid points to be made (and done so
by others) about the actual code you posted, and while I share the
curiousness about the performance of your custom solution compared to
the off-the-shelf alternative, please ignore the trash talk. It's
something that appearantly comes with usenet territory. It's been in
fashion with some for years now, and it will probably outlive us all,
but after a while it's easier living with this minor nuisance than with
a boil on your behind or mosquitoes in the bedroom at night.
And, of course, there's always that shred of hope we will all once see
the light and are allowed to join the ranks of those miscomprehended
superheroes ;-)

GL
Sh.

Thanx SH.. I'm just waiting for that future HR company to google/
keyword this thread when dear ol' Steve looks for a job.
Yea, that will be lovely, won't it? ROFLMAO!

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 19 '07 #49
On Apr 19, 12:03 pm, "Steve" <no....@example .comwrote:
| Thanx SH.. I'm just waiting for that future HR company to google/
| keyword this thread when dear ol' Steve looks for a job.

you really are a clueless fuckwit!

exactly WHAT would they be searching/keywording for? and exactly HOW would
they know 'Steve' was the applicant in front of them? wait, lemme guess...on
your resume in bold at the top, it reads: COMP.LANG.PHP (like a dumbass).

get a fucking clue. even if they did (which is IMPOSSIBLE), they'd certainly
agree that your code is shit. they may want me to tone down what name i use
for said rose, but we'd wink everytime we used the substitute.

as it is, my fte has enjoyed having me as an employee for about seven years
now. my pte has as well in a consultant position...unde r which contract, i
am on retainer. that should suggest to you that i have a *very* good
relationship there since they pay me each month regardless of whether i work
for them during that time or not - they know that whenever i do and for
whatever it is they have me do, i get it done. i've been pte this way for
two years now. and, except for my first consulting gig, all my pte contracts
have been by reference.

all that should tell you something; that you are wrong. even more, that you
should revisit the initial advice i gave you before the name calling
started, since it may be that i actually do know what i'm talking about.

either way:

*PLONK*
Enjoy your cowardly anonymity while it lasts. You can be found out, I
promise you that.

Plonk.. wow.. but thank you for being my favorite laugh riot for the
week!

Apr 19 '07 #50

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
2066
by: Phil Powell | last post by:
I borrowed this code from a source: for($a=0;$a<imagecolorstotal ($image_id);$a++) { $color = imageColorsForIndex($image_id,$i); $R=.299 * ($color)+ .587 * ($color)+ .114 * ($color); $G=.299 * ($color)+ .587 * ($color)+ .114 *
22
3140
by: Fabian | last post by:
var preload1 = new Image(); preload1.src = "/pic/yay.gif"; var preload2 = new Image(); preload2.src = "/pic/nay.gif"; The above is meant to preload image files, yes? Problem is, it doesnt seem to be doing so in practice. Any idea where Im going wrong? Could it be that things work differnetly when in an attached .js file? -- --
0
2335
by: styler | last post by:
I am having difficulty with the page located here: http://tinyurl.com/2zwa9 I am creating a number of image sets (some left-, some right-aligned; an example of the right-aligned is shown the first figure below) in which the text accompanying the image sets flows down around them. The image sets have a single image on top and two immediately below. To create the effect, I contain the image on top in a DIV and float it, and the bottom...
2
2122
by: billrdio | last post by:
I am trying to make a JavaScript animation of real-time images - i.e. images that will periodically change on the server. The problem I am having is that the JavaScript animation I have created is always using the images from the cache, even though I have set the HTTP response header on the server (via .htaccess) so that the browser should validate the image in the cache against the image on the server for freshness. I have tested the...
7
11066
by: bbxrider | last post by:
there is some property that i think is mostly used for images used as backrounds that fades them, so you can get the idea of the image but not have it obscuring the text thats on it, its not trasparency i have been going nuts trying to find it, i'm sure i've seen it described somewhere on the w3c site but embarrassed to say can't find it again hopefully somebody knows this or maybe i'm going crazy
3
2683
by: yawnmoth | last post by:
http://us2.php.net/manual/en/function.imagegif.php#20425 The above URL suggests that it's possible to sorta embed images within an HTML document so that they don't have to be loaded via a seperate HTTP request. The idea intrigues me, although I can't seem to get it working. Is the idea sound or is that link just kinda bogus? Here's my (failed) attempt: http://www.geocities.com/terra1024/inline_gif.html
12
2849
by: comp.lang.php | last post by:
index.php: // STUFF // STEP 1: imagecreatetruecolor ONLY IF GD 2.0+ SUPPORTED AND FOUND if ($this->isSuccessful && !$hasMogrified && $image && !$newImage && function_exists('imagecreatetruecolor') && preg_match('/2\.0/i', $this->gd_info_array)) { $newImage = @imagecreatetruecolor($configArray, $configArray);
2
1772
by: utahwrx | last post by:
I currently have a Javascript application that randomizes about 200 images. The problem is that the images preload, which causes the entire site to not come up until all the images are loaded. I'd like to find a Javascript application that can load images as they are randomly chosen. In addition, I'm trying to figure out how to not display the same image more than once; or at least until after the 200 have been displayed, then create a new...
11
2358
by: eholz1 | last post by:
Hello PHP group, I am using some php code to check the size of images, and then resize or determine new dimension for the image. GD seems quite slow. It takes about 5 seconds (plus or minus) to calulate dimension for 7 jpeg images. I have a 700mhz processor (Pentium III, remember those??)! with almost a gb of memory. Is that the way GD is??? Here is a snippet of the dode I use: I pass
0
9716
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9596
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10604
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10356
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10361
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9179
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5676
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3839
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3006
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.