Image Problem with PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
glenn
Forum Newbie
Posts: 18
Joined: Fri Apr 19, 2002 7:42 am
Location: London, England (UK)

Image Problem with PHP?

Post by glenn »

Hello Everyone!!

I just can't get this working (which is <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> me off!). Altough I have been working with PHP for about 6 to 8 months now, my in deepth details of it suck!! So I thought I would build a web site using PHP. I have lots of ideas about what I wanted to do, one of them was to have a "Settings" option on the home page to change the background colour! Which I have working I can do that but I have two jpeg images on the home page which still have the defualt background colour on them!! As you can see form my script from below I have the RGB of my defualt colour (#CC9900) but all my script does is nothing!!! I have tried again and again to sort this problem out but can't!! What I can't seem to get myt head around is how can imagefill() work when I have not given it another colour to change the one that imagecolorallocate() is asked to find!? I have type it up wrong or are there better ways in which to to this? The colour I want the edges to be changed to are put into a cookie ($back), can anyone help??


if (!($image = @imagecreatefromjpeg("home1.jpg"))) {
$colorBack = imagecolorallocate($image, 204, 153, 0);
imagefill ($image, 0, 0, $colorBack);
header ("Content-type: image/jpeg");
imagejpeg($image);
} else {
print ("Can't load image!");
}


Glenn Curtis.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

maybe you should use an image-format that supports transparency (e.g. png). Then there's no need for that script ;)
glenn
Forum Newbie
Posts: 18
Joined: Fri Apr 19, 2002 7:42 am
Location: London, England (UK)

Post by glenn »

I thought of that!! But I can't use gif as they are Photoshop edited photos and need that quilty of jpeg! I have not used png much but I did hear that some browsers had problems with the png format and that it was best to stick to jpeg but that was some time ago!


Thanks for your help, thats what I was think about doing anyway!!!

Glenn Curtis.
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

The problem I see here is that your original JPEG has it's own background colour. Unfortunately you can't replace the background of a JPEG whitout bringing it in Photoshop (or other) and manually changing the colour.

Does it have to be a user specified colour, (the user chooses the 336699 colour for exemple and another chooses 345678) or do you give a choice?

If you specify the choices then I would suggest that you create a separate image for each colour.

Otherwise you could always reconstruct the image from the various pieces used, if you store locally the image elements in TIFF format you could reconstruct the image, specifying the new background colour and then export it as JPEG.

I'm throwing ideas out here. I haven't had to try anything like this...

BTW Have you checked this function? http://www.php.net/manual/en/function.imagecolorset.php
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

some browser still have problems with certain aspects of PNG. But support for simple transparency is (afaik) good.
you might check the capabilities of different browsers e.g. at http://www.libpng.org/pub/png/pngsuite.html
glenn
Forum Newbie
Posts: 18
Joined: Fri Apr 19, 2002 7:42 am
Location: London, England (UK)

Post by glenn »

Thanks puckeye,

I think I will give you idea about having a pic for each of the colours that can be selected as I will be using a list of about 4 -6 colours. I think that I can sort that out on my own but maybe posting here again if I can't!!!!

Volka, with PNG I think I will use it only as a last resort, although I am only testing may sites on Netsacpe and IE and maybe opera. I would have thought that they would not have any probelms but I dont want to rule out people with other ones, if I can get around it!

P.S - I only have a Windows based PC and would like to know if Linux with Netsacpe rans any different to a windows paltform?

Thanks for all your help.

Glenn Curtis
Post Reply