Hello,
I'm trying to make a gif image out of a total of 5 (currently) images. One background image and 4 small icons.
This image also includes text of a specific font.
Here are my issues.
First... the background image is in color and looks correct. The icons that I merge onto the background image are in black and white. I'm not sure why this is happening. This happens on both my development environment and on my server.
Second... The text is working in my development environment, but when I move the file to the server, the text does not display.
Development Environment:
Win XP Pro SP2
PHP 4.4.4
GD 2.0.28
Server
Linux
PHP 5.2.0
GD 2.0.28
I should probably mention that when I use png for all of the images it works fine in both my development environment and on my server, however I'm trying to use gif files for transparency reasons since IE doesn't handle png transparencies.
[php]<?php
header ("Content-type: image/gif");
$id = $_GET['id'];
if ( strlen( $id) < 1 ) {
$id= "MissingID";
}
// Defining the background image.
$background = imagecreatefromgif("ps3gamertag-blankgif.gif");
// colors to possibly be used later
$white = imagecolorallocate($background, 255, 255, 255);
$almostWhite = imagecolorallocate( $background, 247, 247, 247 );
// Defining the icons to be added or combined.
$insert = imagecreatefromgif( "icon1.gif" );
$insert2 = imagecreatefromgif( "icon2.gif" );
$insert3 = imagecreatefromgif( "icon3.gif" );
$insert4 = imagecreatefromgif( "icon4.gif" );
// Get icon width and hight for later use
// all icons are the same size
$insert_x = imagesx($insert);
$insert_y = imagesy($insert);
// Combine the images into a single output image.
imagecopymerge($background,$insert4,312,45,0,0,$in sert_x,$insert_y,99);
imagecopymerge($background,$insert2,350,45,0,0,$in sert_x,$insert_y,99);
imagecopymerge($background,$insert3,388,45,0,0,$in sert_x,$insert_y,99);
imagecopymerge($background,$insert,426,45,0,0,$ins ert_x,$insert_y,99);
// Add id text
imagettftext( $background, 12, 0, 35, 76, $almostWhite, "Concf.ttf", $id);
// Output the results as a gif image, to be sent to users browser.
imagegif($background);
imagedestroy($background);
?>[/php]
Thoughts?
9 3758
The imagecreatefromgif may be imposing color restrictions on your original image. Just create an image with imagecreate and draw a colored rectangle for your background.
The imagecreatefromgif may be imposing color restrictions on your original image. Just create an image with imagecreate and draw a colored rectangle for your background.
Before posting here, I tried this...
[php]
$tempimage = imagecreatetruecolor($insert_x, $insert_y);
// copy the 8-bit gif into the truecolor image
imagecopy($tempimage, $insert2, 0, 0, 0, 0,$insert_x, $insert_y);
// copy the source_id int
$insert2 = $tempimage;[/php]
That didn't work.
I also tried it using imagecreate() instead of imagecreatetruecolor().
Do I need to set a color to the image first beforehand?
Any thoughts on the text?
I think this line:
$background = imagecreatefromgif("ps3gamertag-blankgif.gif");
Is giving you the problem.
I believe that your target's color depth ($background's color depth) is set wrong. Try replacing that with createimagetruecolor.
I think this line:
$background = imagecreatefromgif("ps3gamertag-blankgif.gif");
Is giving you the problem.
I believe that your target's color depth ($background's color depth) is set wrong. Try replacing that with createimagetruecolor.
Motoma... Thanks a lot!
This worked for me! Unfortunatly it brought up another problem.
My icons are now showing in color.
My text is now showing up too.
However, transparencies are no longer working.
Here's what I've tried so far.
[php] $background = imagecreatefromgif("blankgif.gif");
$background_x = imagesx( $background );
$background_y = imagesy( $background );
$tempimage = imagecreatetruecolor($background_x, $background_y);
imagesavealpha($tempimage, true);
$trans_colour = imagecolorallocatealpha($tempimage, 255, 0, 0, 127);
imagefill($tempimage, 0, 0, $trans_colour);
imagecopymerge($tempimage, $background, 0, 0, 0, 0,$background_x, $background_y,99);
$background = $tempimage;[/php]
I also tried this...
[php] $background = imagecreatefromgif("blankgif.gif");
$background_x = imagesx( $background );
$background_y = imagesy( $background );
$tempimage = imagecreatetruecolor($background_x, $background_y);
$tempcolor = imagecolorallocate($tempimage, 255, 0, 0);
imagefill($tempimage, 0, 0, $tempcolor);
imagecolortransparent($tempimage, $tempcolor);
imagecopymerge($tempimage, $background, 0, 0, 0, 0,$background_x, $background_y,99);
$background = $tempimage; [/php]
I'm still looking for other stuff to try, but if you have any suggestions... I'd be very appreciative.
I'm sorry to keep bothering you with this stuff, but I'm still trying to figure out all the little quirks of GD.
However, transparencies are no longer working.
I'm still looking for other stuff to try, but if you have any suggestions... I'd be very appreciative.
I'm sorry to keep bothering you with this stuff, but I'm still trying to figure out all the little quirks of GD.
When you say transparencies are no longer working, do you mean for the base image ($background), or the images you are placing on top? You may need to enable transparency on all images.
You don't have to apologize for asking questions, that's what we are here for!
When you say transparencies are no longer working, do you mean for the base image ($background), or the images you are placing on top? You may need to enable transparency on all images.
You don't have to apologize for asking questions, that's what we are here for!
Thanks a lot! :)
I mean the resulting image. The $background image is built on a transparency. the icons are placed on top of the $background. The createimage() is what I want to now be transparent and the two methods I posted did not work.
Any ideas?
Thanks a lot! :)
I mean the resulting image. The $background image is built on a transparency. the icons are placed on top of the $background. The createimage() is what I want to now be transparent and the two methods I posted did not work.
Any ideas?
Taking a look at your second example from the last code you posted:
You may either need to use imagealpha() on $background, or use imagecolortransparent() on a color from $background. You see, you are grabbing a color index from one image, and referring to that color index in a different image. This may be the source of your problem.
Taking a look at your second example from the last code you posted:
You may either need to use imagealpha() on $background, or use imagecolortransparent() on a color from $background. You see, you are grabbing a color index from one image, and referring to that color index in a different image. This may be the source of your problem.
*sigh* This was frustrating Motoma
You were absolutely right.
I was using the temp image when defining the color to make the transparency. When I changed that... it worked... ... ... in my dev env.
As soon as I transfered it over to the server. The background color returned.
So I did some more research and got it going.
For some reason, when I filled the createimage() with a statically defined color, and then tried to transparent it, it wouldn't work. But if I went and got the color at 0,0 on the back ground image, set that to the temp color, filled the createimage with that, then transparent it, it works.
Anyway... here's the result...
[php] $background = imagecreatefromgif("blankgif.gif");
$background_x = imagesx( $background );
$background_y = imagesy( $background );
$tempimage = imagecreatetruecolor($background_x, $background_y);
$tempcolor = imagecolorat($background, 0, 0);
imagefill($tempimage, 0, 0, $tempcolor);
imagecopymerge($tempimage, $background, 0, 0, 0, 0,$background_x, $background_y, 99);
$background = $tempimage;
imagecolortransparent($background, $tempcolor); [/php]
Thanks a lot for all your help. I now know where to come for advice when I'm having issues!
Chris
Boy, I am glad you were able to get your solution. Come back any time you have a question.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: bof |
last post by:
I'm attempting to use ImageTTFText to render text to an image, I can get
it to work if I
a) specify the full font path
b) switch off anti-aliasing
c) specify an OpenType font (e.g. arial.ttf)
...
|
by: John Wellesz |
last post by:
Hi,
since I've upgraded to php 4.3.4 (before I used 4.1.2) I have a problem
with imagettftext():
when executing the line:
imagettftext($im, 20, 0, 10, 25, $white, "$script_dir/verdana.ttf",...
|
by: Doug Farrell |
last post by:
Hi all,
I'm trying to use the PHP GD functions to make graphical changes to
image files. In particular I'm trying to add a 'highlight' rectangle
to an image. So far everything I've tried doesn't...
|
by: Leif Wessman |
last post by:
From: http://www.php.net/manual/en/function.imagettftext.php
"color is the color index. Using the negative of a color index has the
effect of turning off antialiasing."
I'm using a bundled...
|
by: ljb |
last post by:
Using PHP-4.3.11 with GD extension, bundled GD library, and freetype-2.1.9
(with X.org 6.8.1). I can't get the TrueType Font (TTF) bounding box to
come out right. Whether using imagettftext() or...
|
by: Gordan |
last post by:
Im using imagettftext to write some text on my image. I'm on Win XP and using
the plain arial.ttf font that I copied from win dir
my typical line would be
imagettftext($im, 33, 0, 20, 500, $black,...
|
by: franscescomoi |
last post by:
Hi.
On PHP 4.3.10 on Linux I try to:
------
$im = imagecreate(400, 30);
$black = imagecolorallocate($im, 0, 0, 0);
imagettftext($image, 20, -3, 10, 20, $black, 'Arial.ttf', 'Test');
-------
...
|
by: monomaniac21 |
last post by:
My url is www.aptitudehack.com
Hi i cant get an image to display on another server though it does on
mine. Here is the code for the page. The problem i think is the
imagettftext function...
|
by: fishwick |
last post by:
I haven't really done any css in quite a while, and am banging my head
against the wall trying get the rudimentary layout together of a church
website home page to display correctly - I don't want...
|
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
|
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: 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: 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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
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...
|
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...
| |