473,806 Members | 2,717 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GD_Image, imagecopyresamp le, dithering the transparent color

Hello - I'm using imagecopyresamp le() 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($i mage, $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($i mage, $x, $y);

$rgb = imagecolorsfori ndex($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 1788

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

Similar topics

5
4088
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 100% however my right most image on my "nav bar" when set to width=100% it gets a really bad dithering or pixelating effect . I have tried converting the image from a gif to jpg (as I have seen alot of the sites use jpg for this ) to no avail....
8
6496
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 IE or Firefox. I have tried GIF and PNG with 'binary' transparency and PNG24 with 'alpha' transparency (obviously the latter won't work in IE without the AlphaImageLoader trick). Here is a test page for you to see it not working in action:
1
20185
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 I prefer don't insert a background in MyComponent, and using the MyApp one as general background with MyComponent positionned, but I am not able to have MyComponent background transparent.
3
3109
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 Whiteboard. The Form contains 3
7
3593
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 to. Thus, when I set White to the transparent color of a Bitmap stored in the Image of a PictureBox and placed the PictureBox on a Form which has a BackColor of black, it turned the white pixels of the bitmap image to black, but these black pixels...
8
10612
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 some controls that aren't rectangular and it won't be pretty if I end up with a grey rectangle behind each one. http://msdn.microsoft.com/library/en-us/vbcon/html/vbtskGivingYourControlTransparentBackground.asp?frame=true
4
2566
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 lblP1JoyRight.BackColor = clrLabelMove
4
9378
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 written on the glass pane. i need to be able to see the control or form that is underneath the RichTextbox, and at the same time to be able to write and erase text to the RichTextbox. i'm assuming that it is the backcolor that hides what is...
5
2017
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) {
0
9719
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
10624
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
10371
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
10374
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
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5684
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3010
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.