Ok ive been wracking my brains over this for absolutely ages and cant find a simple answer anywere not even on the php.net site so i was wondering if you could help me.
I have designed a gif file in photoshop with transparent backgrounds, but when i use
[PHP]$im = imagecreatefromgif($imgname)[/PHP]
the transparent images are showing up as white and i cant seem to figure out how to keep the transparent background within the new image.
Surrounding Code
[PHP]
$im = imagecreatefromgif($imgname);
$imsize = getimagesize($imgname);
$colorTransparent = imagecolortransparent($im);
$im2 = imagecreate($imsize['0'],$imsize['1']);
imagepalettecopy($im2,$im);
imagefill($im2,0,0,$colorTransparent);
imagecolortransparent($im2, $colorTransparent);
imagecopyresized($im2,$im,0,0,0,0,$imsize['0'],$imsize['1'], $imsize['0'], $imsize['1']);
[/PHP]
I would be most appreciative if someone can help me with this cus ive been looking for hours and cant find anything.
Kind Regards
Devon
2 2868
Hi,
The image, do you display it in a browser? In that case what browser?
I've seen similar cases where the transparent area goes black or white.
/MK
Atli 5,058
Expert 4TB
Hi.
I remember testing this, and the only way I could keep the transparency was to set the transparent color (via imagecolortransparent) of the new image to black.
Seeing as your backgrounds are showing white, maybe this should be white in your case.
Trying to get the transparent color of the original image (like you do) never worked.
This worked for me: -
<?php
-
// Create original container
-
$original = imagecreatefromgif($pathToOriginal);
-
-
// Calculate new size
-
$imgSize = getimagesize($pathToOriginal);
-
$newx = $imgSize[0] * 0.25;
-
$newy = $imgSize[1] * 0.25;
-
-
// Create copy container
-
$copy = imagecreate($newx, $newy);
-
-
// Set transparent as black
-
$cBlack = imagecolorallocate($copy, 0, 0, 0);
-
imagecolortransparent($copy, $cBlack);
-
-
// Copy
-
imagecopyresampled($copy, $original, 0, 0, 0, 0, $newx, $newy, $imgSize[0], $imgSize[1]);
-
?>
-
I never used it because it didn't seem reliable, but under controlled circumstances it might work.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Shiperton Henethe |
last post by:
Dreamweaver 4
Hi
Can anyone recommend a decent utility for compressing
HTML that is safe - i.e. that *definitely* doesn't mess
with the appearance in any browsers.
I run a growing website...
|
by: Jim |
last post by:
Now this is just weird. And yes, I validated the html and the stylesheet.
I created a transparent gif image in Paint Shop Pro 7. I made the mistake of making a
transparent png and went along...
|
by: Michael Rozdoba |
last post by:
I've had some trouble getting IE to behave in respect of applying
absolute positioning to a span on an a:hover. I can get it to work, but
I don't understand why certain code causes it to fail to...
|
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...
|
by: Chris Tremblay |
last post by:
I am trying to create an image using GDI+ in VB.NET. I want to have the
background be transparent, but when I do run the following:
myGraphicsObject.clear(color.transparent)
the resulting...
|
by: Mark Deibert |
last post by:
I'm a former VB6 coder. Quit a few years ago. Now I'm back and trying
to teach myself VB.NET. I don't remember having this much difficulty
learning VB6. I'm totally stuck on something and need your...
|
by: RCS |
last post by:
I'm working on an ASP.NET webpage that generates an image (and am using VWD
2005 until my copy of VS2005 ships). I have done all the obvious (and
not-so-obvious) things to try to give a gif that I...
|
by: Trond Michelsen |
last post by:
Hi.
I have a transparent PNG-image that I would like to display on top of
the rest of the web page. I've already got this part working. But, I'd
like the background (as in "the part of the image...
|
by: salmobytes |
last post by:
Making thumbnail images isn't all that hard, for the most
part. There is lots of shrink-wrapped code out there you
can download and/or munge from. But nothing I've yet
seen does the right thing...
|
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...
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
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: 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,...
|
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,...
|
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...
|
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...
| |