473,378 Members | 1,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

GD_Image, imagecopyresample, dithering the transparent color

Hello - I'm using imagecopyresample() to resize a GIF line-art type
image onto a polygon created with GD_Image in PHP. Each has a
transparent color (same color, I think!). The transparent color is
dithering during the resize, though. Result is, some pixels aren't
transparent anymore until I search the whole image for colors close
rgb-wise to the original transparent color, and put it back to
transparent. This color replacement step is a 400% performance hit in
my case (these aren't huge images).

Is there a way to just dither the non-transparent colors?

Or can I more easily find/replace the dithered colors back to the
original color? Here's the color replace function:

// replace a color with a new color
function change_color($image, $old_color, $new_color, $threshold) {
$image_width = imagesx($image);
$image_height = imagesy($image);

$r_old = ($old_color >16) & 0xFF;
$g_old = ($old_color >8) & 0xFF;
$b_old = $old_color & 0xFF;

// iterate through x axis
for ($x = 0; $x < $image_width; $x++) {

// iterate through y axis
for ($y = 0; $y < $image_height; $y++) {

// look at current pixel
$pixel_color = imagecolorat($image, $x, $y);

$rgb = imagecolorsforindex($image, $pixel_color );

$delta = abs( $rgb['red'] - $r_old ) + abs( $rgb['green'] -
$g_old ) + abs( $rgb['blue'] - $b_old );

// sum RGB deltas, and compare to thresh
if ( $delta <= $threshold && $delta != 0 ) {
// replace with new color
imagesetpixel($image, $x, $y, $new_color);
}

}
}
}

Oct 22 '07 #1
0 1765

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

Similar topics

5
by: David S. | last post by:
Hello all, I am trying to create my first website that is screen resolution(height/width) and browser width friendly .. I have a basic design done in fireworks and I converted the table size to...
8
by: djmanmaster | last post by:
Am I right in thinking that images with transparent areas (GIFs or PNGs) should allow clicks to "pass through" to any underlying elements behind them? I have had no luck getting this to work in...
1
by: Efkas | last post by:
My application have some level : 1. MyButton class with Label inheritance 2. MyComponent as User Control loading and positionning some of MyButtons 3. MyApp loading and positionning MyComponent ...
3
by: Steve Koon | last post by:
Any thoughts on getting this project to work or suggesting another method would be appreciated. Steve ========================================== Project: A Windows Form which acts as a...
7
by: Peter Oliphant | last post by:
Using MakeTransparent one can supposedly turn a color used in a Bitmap to transparent. But, it looks to me like all it does it set these pixels to the color BackColor of the Control it's attached...
8
by: Grahammer | last post by:
Is it possible to set the background of a usercontrol as transparent? I tried setting the background image of the usercontrol to a transparent GIF, but that caused MAJOR problems. I'm making...
4
by: jcrouse | last post by:
I am using the following code to move a label on a form at runtime: If myMousedown = lblP1JoyRight.Name Then If lblP1JoyRight.BackColor.Equals(Color.Transparent) Then bTransCk = True ...
4
by: ray well | last post by:
in my app i need to make a RichTextbox control transparent. i need it to be a like a pane of glass lying on a sheet of paper, where u can see everything on the sheet of paper not covered by text...
5
by: macap.usenet | last post by:
Hello, I am creating Gif-Images (8bit: 256 colors) with using the IHttpHandler and .ashx-Files. My ProcessRequest-Method looks like this: public void ProcessRequest(HttpContext context) {
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.