473,545 Members | 2,569 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Transparent image

Hi!

Here's a piece of code:

[begin]

<?php

Header('Content-type: image/png');

$sz = "";

$FileValue = 1000;

$i = strlen($FileVal ue);

for ( $j = 0; $j < 7-$i; $j++ )
{
$sz = $sz . "0";
}

$Img = imagecreate(56, 13);

$Gold = imagecoloralloc ate($Img,148,12 8,100);

$Gray = imagecoloralloc ate($Img,32,32, 32);

ImageFilledRect angle($Img,0,0, 55,12,$Gray);

imagestring($Im g,4,0,0,$sz.$Fi leValue,$Gold);

imagepng($Img);

ImageDestroy($I mg);
?>

[end]

OK. Calling this script I have a png picture back.

Now I add imagecolortrans parent($Img,$Gr ay); just before imagepng() and OK
again, I have a transparent picture back. But now, if I add:

$r = imagerotate($Im g,90,0);

imagepng($r);

just after the imagecolortrans parent() instruction seen above, I get a
rotated picture, but not transparent. How to solve that? I've used a plenty
of tricks, no one works.

Thanx.
Jul 17 '05 #1
6 16633
"AMcD" <ar************ *@free.fr> writes:
<?php
Header('Content-type: image/png');

$sz = "";
$FileValue = 1000;
$i = strlen($FileVal ue);
for ( $j = 0; $j < 7-$i; $j++ )
{
$sz = $sz . "0";
}
This isn't related to your problem, but are you familiar with the
sprintf() function? You're going to a lot of trouble to add leading
zeros when you could just do this:

$str = sprintf("%07d", $FileValue);
$Img = imagecreate(56, 13);
$Gold = imagecoloralloc ate($Img,148,12 8,100);
$Gray = imagecoloralloc ate($Img,32,32, 32);
ImageFilledRect angle($Img,0,0, 55,12,$Gray);
imagestring($Im g,4,0,0,$sz.$Fi leValue,$Gold);
imagepng($Img);
ImageDestroy($I mg);
?>

OK. Calling this script I have a png picture back.

Now I add imagecolortrans parent($Img,$Gr ay); just before imagepng() and OK
again, I have a transparent picture back. But now, if I add:

$r = imagerotate($Im g,90,0);
imagepng($r);

just after the imagecolortrans parent() instruction seen above, I get a
rotated picture, but not transparent. How to solve that? I've used a plenty
of tricks, no one works.


Create the first image with imagecreatetrue color() and then create
the rotated image like this:

$r = imagerotate($Im g, 90, $Gray);
imagecolortrans parent($r, $Gray);

I just tested this and the rotated image had a transparent background.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #2
"AMcD" <ar************ *@free.fr> wrote in message news:<3f******* *************** *@news.free.fr> ...
Hi!
<snip>

I get a rotated picture, but not transparent. How to solve that? I've used a plenty
of tricks, no one works.


The transparent support for PNG is broken in many browsers.
Search the net for more about the politics, workaround, and supporting
broswers, etc.

--
"If there is a God, he must be a sadist!"
Email: rrjanbiah-at-Y!com
Jul 17 '05 #3
ng**********@re diffmail.com (R. Rajesh Jeba Anbiah) writes:
"AMcD" <ar************ *@free.fr> wrote in message news:<3f******* *************** *@news.free.fr> ...

I get a
rotated picture, but not transparent. How to solve that? I've used a plenty
of tricks, no one works.


The transparent support for PNG is broken in many browsers.
Search the net for more about the politics, workaround, and supporting
broswers, etc.


The OP stated that the transparent background works for the original
image, so a broken browser doesn't appear to be the problem. In
another followup I posted a solution that worked for me.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #4
Michael Fuhr wrote:
This isn't related to your problem, but are you familiar with the
sprintf() function? You're going to a lot of trouble to add leading
zeros when you could just do this:

$str = sprintf("%07d", $FileValue);
Err, it was just a quick sample ;o). But thanx for the comment (I'm just
starting with PHP).
Create the first image with imagecreatetrue color() and then create
the rotated image like this:

$r = imagerotate($Im g, 90, $Gray);
imagecolortrans parent($r, $Gray);

I just tested this and the rotated image had a transparent background.


OK, then, you mean a stuff like that?

<?php
Header('Content-type: image/png');
$FileValue = 5000;
$sz = sprintf("%07d", $FileValue);
$Img = imagecreatetrue color(56,13);
$Gold = imagecoloralloc ate($Img,148,12 8,100);
$Gray = imagecoloralloc ate($Img,32,32, 32);
ImageFilledRect angle($Img,0,0, 55,12,$Gray);
imagestring($Im g,4,0,0,$sz.$Fi leValue,$Gold);
$r = imagerotate($Im g,90,$Gray);
imagecolortrans parent($r,$Gray );
imagepng($r);
ImageDestroy($I mg);
ImageDestroy($r );
?>

I tried this stuff yet but... it fails too: no transparency. BTW my ISP uses
GD 1.8.x. Maybe it is related? At least, imagetruecolor isn't supported with
1.8.

Thanx for your help.
Jul 17 '05 #5
R. Rajesh Jeba Anbiah wrote:
The transparent support for PNG is broken in many browsers.
Search the net for more about the politics, workaround, and supporting
broswers, etc.


Not this way dude. All browsers I'm using support transparency and when I
display the "horizontal " transparent PNG picture, there is no problem. I
suspect GD 1.8 instead...

Thanx for helping.
Jul 17 '05 #6
"AMcD" <ar************ *@free.fr> writes:
OK, then, you mean a stuff like that?

<?php
Header('Content-type: image/png');
$FileValue = 5000;
$sz = sprintf("%07d", $FileValue);
$Img = imagecreatetrue color(56,13);
$Gold = imagecoloralloc ate($Img,148,12 8,100);
$Gray = imagecoloralloc ate($Img,32,32, 32);
ImageFilledRect angle($Img,0,0, 55,12,$Gray);
imagestring($Im g,4,0,0,$sz.$Fi leValue,$Gold);
Don't use $sz.$FileValue here -- sprintf() has already put the value
with leading zeros in $sz. You're displaying "0005000500 0", although
you probably don't see that because the image isn't big enough.
$r = imagerotate($Im g,90,$Gray);
imagecolortrans parent($r,$Gray );
imagepng($r);
ImageDestroy($I mg);
ImageDestroy($r );
?>

I tried this stuff yet but... it fails too: no transparency. BTW my ISP uses
GD 1.8.x. Maybe it is related? At least, imagetruecolor isn't supported with
1.8.


Sorry I didn't qualify my previous answer: I'm using GD 2.0.15.
Your example works with that version, so if it doesn't work with
1.8 then perhaps you could convince your ISP to upgrade. According
to phpinfo(), the GD library that comes bundled with recent versions
of PHP is "2.0.15 compatible" so upgrading is easy enough to do,
logistics and potential backward-compatibility problems aside.

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
Jul 17 '05 #7

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

Similar topics

2
13738
by: Fearless Freep | last post by:
I know there's a PIL mailing list but I thought I would try the question here as well. I'm using PIL on Python 1.5.2 (stop laughing, it's what the ISP has for CGI and I don't have a choice) Anyway. I have a basic image and I need to overlay an image on top of it and let some of the basic image show through. Just as an aside the...
4
11633
by: R.Marquez | last post by:
I am trying to create a simple script that Opens an existing PNG and resaves it with a transparent color. With the command line version of ImageMagic this is an easy endevor (and my current solution). I can simply do something like: convert -transparent black image.png image-transparent.png (That makes anything black transparent in the...
1
13107
by: Chris Auer | last post by:
I have been banging my head for a couple of hours now. No matter what I do the color that I make transparent is black. Here is the code I am using from MSDN. I have tried bitmaps, jpegs, gifs and new bitmaps created in code, but I cant get any image to go transparent. Thanks if you can help. // Create a Bitmap object from an image file....
2
5390
by: Raj | last post by:
Hi, Anyone has any idea as to how we can make a button or any standard windows control as transparent or semi-trnasparent. How can we do this in C#? Thanks, Rajendra
5
2530
by: Tony Clark | last post by:
Hi, I have a bmp that is set in a panel, i want to make the white color in the bmp image transparent so i can see the color of the panel below. How is this done? thanks tony
4
10230
by: Dale | last post by:
I am creating GIF images with transparent backgrounds on-the-fly for a web app and rendering them by using System.Drawing.Image.Save(Response.OutputStream, ImageType.GIF). I am confident that the transparency is working properly because if I save the created image to the local hard disk and then view it in a web page or an image editor, the...
9
5843
by: Chuck Anderson | last post by:
Is it possible to overlay a transparent watermark on an image - dynamically? I'd like the result to look like this example: <http://www.cycletourist.com/temp/photo.php> That is a bit of overkill, but you can see what I mean. The watermark image (a png image) is included separately below the photo. I tried using a class from...
3
4860
by: NickP | last post by:
Hi there, I have a usercontrol that inherits from Windows.Forms.Button. In the OnCreateControl method I set the style of the control so that it supports transparent backcolor and set the background color to transparent. ..... Protected Overrides Sub OnCreateControl()
0
1773
by: abc123456 | last post by:
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...
9
4412
by: pek | last post by:
Here is what I want: I have an image, let's say a JPEG 800x600... I want to create a transparent 128x128 PNG image and then resize the 800x600 to fit in the center of my transparent 128x128 PNG.. Can you help me/point me to the right direction..? Thank you very much in advance..
0
7490
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...
0
7425
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...
0
7935
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...
1
7449
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...
0
7780
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...
1
5351
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...
0
5069
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...
1
1911
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
1
1037
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.