473,805 Members | 1,995 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 1740

"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** **************@ o5g2000hsb.goog legroups.com...
| On Apr 16, 12:05 am, "comp.lang. php" <phillip.s.pow. ..@gmail.com>
| wrote:
| On Apr 15, 11:52 pm, "Steve" <no....@example .comwrote:
| >
| | You struck out. imagecopymergeg ray() fails as well, produces a
total
| | non-image with segfault just as much as anything I have done. So
much
| | for your brilliant cocky strategy. Try again.
| >
| well as EVERYTHING i've pointed out as WRONG with the class REMAINS
VALID,
| i'd say i've just stepped up to the plate. if you wanna play
hard-ball, you
| need to be a better pitcher and quit reff-ing since the strike-outs
belong
| to the class creator and NOT me.
| >
| you've merely pitched BALL ONE.
| >
| try again.
|
| Original thread that provided solution:
| http://coding.derkeiler.com/Archive/...4-02/0459.html

i don't care if gawd herself wrote it, it is STILL shit. glad to see though
that PHIL makes an EXACT COPY of SOMEONE ELSE'S code, then puts HIMSELF AS
THE AUTHOR when he (YOU) present it here. no wonder the commented
explanation shows complete lack of understanding of how references work. you
don't understand the code you copied.

BALL THREE.

| >
| You haven't even tried in the first place, or, do you even want to? If
| not, please do not waste bandwith by showing your technological
| bravado and try to help someone out with a problem with grayscaling
| images. How would YOU do it?

btw, it's MY FUCKING BANDWIDTH...go buy your own. until you pay for MINE,
YOU HAVE NO SAY IN HOW I USE IT.
Apr 16 '07 #11

"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** **************@ n76g2000hsh.goo glegroups.com.. .
| On Apr 15, 11:49 pm, "Steve" <no....@example .comwrote:
| "comp.lang. php" <phillip.s.pow. ..@gmail.comwro te in message
| >
| news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
| | How does "for all the 'performance' reasons the brain-dead author
| | gives for creating
| | this beast" help anyone? Thank you for utterly useless ad-hominem
| | information!
| >
| well <as he scratches his head>, it kind of warns you NOT to use the
code,
| as in solving your current problem will not solve the others you will
have
| when you employ this class. but i though that was apparent in the
examples i
| gave to support my opinion.
| >
| i'm now assuming you are said brain-dead author since you glossed over
the
| litany of things-gone-wrong in the code that i pointed out and have
| immediately championed a defensive attitude.
|
| So I assume you feel calling someone "brain-dead" is your way of
| assuming they are receptive to your solutions, whatever they may be,
| which, as I can see, do not yet exist by your means.

you post as 'comp.lang.php' not as PHIL (author of the shitty class).
knowing this know, both of us, does the code change somehow such that it
isn't shitty...enough where i should justifiably refrain from calling it
shitty? having seen that this is NOT PHIL'S code in the first place (thanks
for outting yourself with the link), i can only be MORE correct in the use
of "brain-dead" since you try to pass it off as your own.

BALL FOUR...i can take my base now.

keep racking 'em up, PHIL.
Apr 16 '07 #12
hey genious, here's an RBI:

foreach (
array(
$section ,
'newImage' ,
"${section}_wid th" ,
"${section}_hei ght"
)
as $val
){ $this->$val =& ${$val}; }

what do you intend to do with this lil' gem, eh? you do realize you'll get
the same results by just:

$this->val =& "${section}_hei ght";

ahhh, so when you plagerized the functionality, you copied it
incorrectly...i see.

ROFLMFAO !!!
Apr 16 '07 #13

"Steve" <no****@example .comwrote in message
news:m_******** *******@newsfe0 2.lga...
| hey genious, here's an RBI:
|
| foreach (
| array(
| $section ,
| 'newImage' ,
| "${section}_wid th" ,
| "${section}_hei ght"
| )
| as $val
| ){ $this->$val =& ${$val}; }
|
| what do you intend to do with this lil' gem, eh? you do realize you'll get
| the same results by just:
|
| $this->val =& "${section}_hei ght";

make that:

$this->$val =& ${"${section}_h eight"};

but you get my point. if you want to make the values into variables, do
it...but don't confuse the issue of what $this->$val is. this is right up
there with magic numbers! gotta love coders like you. ;^)
Apr 16 '07 #14
On Apr 16, 1:41 am, "Steve" <no....@example .comwrote:
hey genious, here's an RBI:

foreach (
array(
$section ,
'newImage' ,
"${section}_wid th" ,
"${section}_hei ght"
)
as $val
){ $this->$val =& ${$val}; }

what do you intend to do with this lil' gem, eh? you do realize you'll get
the same results by just:

$this->val =& "${section}_hei ght";

ahhh, so when you plagerized the functionality, you copied it
incorrectly...i see.

ROFLMFAO !!!
It's "genius", BTW.

Apr 16 '07 #15
On Apr 16, 1:47 am, "Steve" <no....@example .comwrote:
"Steve" <no....@example .comwrote in message

news:m_******** *******@newsfe0 2.lga...
| hey genious, here's an RBI:
|
| foreach (
| array(
| $section ,
| 'newImage' ,
| "${section}_wid th" ,
| "${section}_hei ght"
| )
| as $val
| ){ $this->$val =& ${$val}; }
|
| what do you intend to do with this lil' gem, eh? you do realize you'll get
| the same results by just:
|
| $this->val =& "${section}_hei ght";

make that:

$this->$val =& ${"${section}_h eight"};

but you get my point. if you want to make the values into variables, do
it...but don't confuse the issue of what $this->$val is. this is right up
there with magic numbers! gotta love coders like you. ;^)
Coders like me can spell "genius".

Apr 16 '07 #16

"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** *************@l 77g2000hsb.goog legroups.com...
| On Apr 16, 1:47 am, "Steve" <no....@example .comwrote:
| "Steve" <no....@example .comwrote in message
| >
| news:m_******** *******@newsfe0 2.lga...
| | hey genious, here's an RBI:
| |
| | foreach (
| | array(
| | $section ,
| | 'newImage' ,
| | "${section}_wid th" ,
| | "${section}_hei ght"
| | )
| | as $val
| | ){ $this->$val =& ${$val}; }
| |
| | what do you intend to do with this lil' gem, eh? you do realize you'll
get
| | the same results by just:
| |
| | $this->val =& "${section}_hei ght";
| >
| make that:
| >
| $this->$val =& ${"${section}_h eight"};
| >
| but you get my point. if you want to make the values into variables, do
| it...but don't confuse the issue of what $this->$val is. this is right
up
| there with magic numbers! gotta love coders like you. ;^)
|
| Coders like me can spell "genius".

double-entandre dimwit
Apr 16 '07 #17
"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
| On Apr 16, 1:41 am, "Steve" <no....@example .comwrote:
| hey genious, here's an RBI:
| >
| foreach (
| array(
| $section ,
| 'newImage' ,
| "${section}_wid th" ,
| "${section}_hei ght"
| )
| as $val
| ){ $this->$val =& ${$val}; }
| >
| what do you intend to do with this lil' gem, eh? you do realize you'll
get
| the same results by just:
| >
| $this->val =& "${section}_hei ght";
| >
| ahhh, so when you plagerized the functionality, you copied it
| incorrectly...i see.
| >
| ROFLMFAO !!!
|
| It's "genius", BTW.

coming around the home stretch...ahhh, slides right in for another. that's 2
for home, visitors...zilc h.

you'se awr a brittun.

entendre^2...pe rhaps you've heard of it?
Apr 16 '07 #18
Steve wrote:
"comp.lang. php" <ph************ **@gmail.comwro te in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
| On Apr 16, 1:41 am, "Steve" <no....@example .comwrote:
| hey genious, here's an RBI:
| >
| foreach (
| array(
| $section ,
| 'newImage' ,
| "${section}_wid th" ,
| "${section}_hei ght"
| )
| as $val
| ){ $this->$val =& ${$val}; }
| >
| what do you intend to do with this lil' gem, eh? you do realize you'll
get
| the same results by just:
| >
| $this->val =& "${section}_hei ght";
| >
| ahhh, so when you plagerized the functionality, you copied it
| incorrectly...i see.
| >
| ROFLMFAO !!!
|
| It's "genius", BTW.

coming around the home stretch...ahhh, slides right in for another. that's 2
for home, visitors...zilc h.

you'se awr a brittun.

entendre^2...pe rhaps you've heard of it?

Sorry, Steve. I agree with comp.lang.php. You added absolutely nothing
to this conversation except taking up bandwidth. And it's my bandwidth,
also.

I'm glad he got this fixed in spite of your immature language and attitude.

For your next post try alt.anal.orific es. It matches you perfectly.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===
Apr 16 '07 #19
On Apr 16, 7:23 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
Steve wrote:
"comp.lang. php" <phillip.s.pow. ..@gmail.comwro te in message
news:11******** **************@ y80g2000hsf.goo glegroups.com.. .
| On Apr 16, 1:41 am, "Steve" <no....@example .comwrote:
| hey genious, here's an RBI:
| >
| foreach (
| array(
| $section ,
| 'newImage' ,
| "${section}_wid th" ,
| "${section}_hei ght"
| )
| as $val
| ){ $this->$val =& ${$val}; }
| >
| what do you intend to do with this lil' gem, eh? you do realize you'll
get
| the same results by just:
| >
| $this->val =& "${section}_hei ght";
| >
| ahhh, so when you plagerized the functionality, you copied it
| incorrectly...i see.
| >
| ROFLMFAO !!!
|
| It's "genius", BTW.
coming around the home stretch...ahhh, slides right in for another. that's 2
for home, visitors...zilc h.
you'se awr a brittun.
entendre^2...pe rhaps you've heard of it?

Sorry, Steve. I agree with comp.lang.php. You added absolutely nothing
to this conversation except taking up bandwidth. And it's my bandwidth,
also.

I'm glad he got this fixed in spite of your immature language and attitude.
Thank you, Jerry, very nice to hear this! Unfortunately no I never
did solve the problem; I am still not capable of grayscaling an image:

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

for ($y = 0; $y < $this->{$section . '_height'}; $y++) {
for ($x = 0; $x < $this->{$section . '_width'}; $x++) {
$ndx = @imagecolorat($ this->$section, $x, $y);
$red = ($ndx >16) & 0xFF;
$green = ($ndx >8) & 0xFF;
$blue = $ndx & 0xFF;
//$ndxColorArray = @imagecolorsfor index($this->$section, $ndx);
//$avg = floor(($ndxColo rArray['red'] + $ndxColorArray['green'] +
$ndxColorArray['blue']) / 3);
$col = $red * 0.299 + $green * 0.587 + $blue * 0.114;
@imagesetpixel( $this->$section, $x, $y, $colorNDX[$col]);
}
}

//@imagecopy($thi s->newImage, $this->$section, 0, 0, 0, 0,
// $this->{$section . '_width'}, $this->{$section .
'_height'});

}

No image is ever produced in spite of the code produced.
>
For your next post try alt.anal.orific es. It matches you perfectly.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstuck...@attgl obal.net
=============== ===

Apr 16 '07 #20

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
11067
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
10607
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
10359
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...
0
9182
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
6875
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5541
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5677
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3843
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.