473,498 Members | 1,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

setting imagecreatetruecolor() to have transparency as default

Does anyone know if its possible to set imagecreatetruecolor() to initialise
with transparency
rather than black?
Maybe a cunning work-around?


May 21 '06 #1
4 6411
"Chamomile" <ne********@chamomile.co.uk> wrote in message
news:ir******************************@bt.com...
Does anyone know if its possible to set imagecreatetruecolor() to
initialise
with transparency
rather than black?
Maybe a cunning work-around?

It's mentioned in the user comments in php.net manual page:
http://fi.php.net/manual/en/function...olor.php#54025

// Creates a transparent image rather than the default black image
function imageCreateTransparent($x, $y) {
$imageOut = imagecreate($x, $y);
$colourBlack = imagecolorallocate($imageOut, 0, 0, 0);
imagecolortransparent($imageOut, $colourBlack);
return $imageOut;
}

HTH

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
May 22 '06 #2
>
It's mentioned in the user comments in php.net manual page:
http://fi.php.net/manual/en/function...olor.php#54025

// Creates a transparent image rather than the default black image
function imageCreateTransparent($x, $y) {
$imageOut = imagecreate($x, $y);
$colourBlack = imagecolorallocate($imageOut, 0, 0, 0);
imagecolortransparent($imageOut, $colourBlack);
return $imageOut;
}

HTH

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)

Yes, thanks - I came accross that.
The problem is, it only makes a non-truecolor image which is no good for my
purposes
as I am downsampling with imagecopyresample() in order to get 'aliased'
curve fills at small sizes.
- downsampling an image made using imagecreate() gives jagged curves,
whereas downsampling using imagecreatetruecolor() gives good smoothing.
Unfotunately it seems once an image has ever been truecolor - even if you
theoretically set it back to paletted colors
(as far as I can see with experimentation) you cannot re-set the
transparency of the 'black' areas.

It seems to be a choice between smoothed curves or transparency - not both!
May 22 '06 #3
NC
Chamomile wrote:

Does anyone know if its possible to set imagecreatetruecolor()
to initialise with transparency rather than black?


My first instinctive reaction would be to say no. Transparency is
supported in GIF and PNG formats, but not in JPEG. So when you attempt
to create an image that doesn't yet have a format associated with it,
you shouldn't expect it to contain features specific to a format you
have not yet defined...

Cheers,
NC

May 22 '06 #4
"Chamomile" <ne********@chamomile.co.uk> wrote in message
news:OJ********************@bt.com...
Yes, thanks - I came accross that.
The problem is, it only makes a non-truecolor image which is no good for
my
purposes
as I am downsampling with imagecopyresample() in order to get 'aliased'
curve fills at small sizes.
- downsampling an image made using imagecreate() gives jagged curves,
whereas downsampling using imagecreatetruecolor() gives good smoothing.
Unfotunately it seems once an image has ever been truecolor - even if you
theoretically set it back to paletted colors
(as far as I can see with experimentation) you cannot re-set the
transparency of the 'black' areas.

It seems to be a choice between smoothed curves or transparency - not
both!


A slight modification to the original sample seems to answer the question.

<?php

header('Content-type: image/png');
$imageOut = imagecreate(100, 100);
$colourBlack = imagecolorallocatealpha($imageOut, 0, 0, 0, 127);
imagepng($imageOut);

?>

This worked for me so that when I saved the image and opened it in photoshop
it really was transparent. The solution apparently is that the first color
you allocate defines the background of the image. Now if you use
imagecolorallocatealpha and give 127 as the alpha channel, you'll get a
truecolor image with completely transparent bg.

HTH, again ;)

--
"ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" -lpk
sp**@outolempi.net | Gedoon-S @ IRCnet | rot13(xv***@bhgbyrzcv.arg)
May 23 '06 #5

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

Similar topics

2
5649
by: Cecile Muller | last post by:
I've been trying to just open a png and display it, that way: <? header ("Content-type: image/png"); $im = imagecreatefrompng('empty.png'); imagepng($im); ?> But the transparency is not...
2
6651
by: chotiwallah | last post by:
there seems to be a maximum size (in px) for images created with imagecreatetruecolor (somewhere between 4000 px and 4500 px). if the image is bigger than that size, the browser doesn't display it...
2
4840
by: Robin Becker | last post by:
Has anyone done transparency with PIL & TIFF? I'm using PIL to generate a preview TIFF for embedding into an eps file and am being asked for the TIFF to support transparency. -- Robin Becker
4
1709
by: James Dean | last post by:
I am trying to directly set the pixels in a 32ARGB image but for some reason i am not setting them correctly. I have a struct 4 bytes in size... public struct PixelData { public byte Blue;...
0
1523
by: Chamomile | last post by:
Does anyone know if its possible to set imagecreatetruecolor() to initialise with transparency rather than black? (using png...) Maybe a cunning work-around?
12
2801
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 &&...
1
6435
by: laredotornado | last post by:
Hi, I'm using PHP 4.4.4 on Apache 2 on Fedora Core 5. PHP was installed using Apache's apxs and the php library was installed to /usr/local/php. However, when I set my "error_reporting"...
0
1287
by: ZikO | last post by:
Hi. I've experienced one problem. Im using three froms. Two of them are maximized, whereas one is normal form with transparency. Transparency stops working, that is I can see the color which...
1
2692
by: dragze | last post by:
Hi, On one of the pages of my site i use two javascripts, one makes transparency of png's work in IE, and the other embeds a flash player. Now use one of the scripts it works fine, use both and...
0
7004
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...
0
7167
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,...
0
7208
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...
1
6890
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...
0
7379
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...
0
3095
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...
0
1423
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 ...
1
657
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
292
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...

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.