As part of my new site, users will get images to share accross the internet. These images are created dynamically and get the information/statics from my database.
One of these is a review field, and rather than have x/5 Stars as text, I'd rather have it as an image - inside the other image.
I've had a quick look through Google, and the PHP manual, but can't seem to find anything - Does anyone know the function, or if it even exists?
Well Do you know how to make images? If you do then you should be able to impliment imagecopymerge to copy a star onto your pics.
Once you have that mastered all you need to do it make and if statement.
| Code: |
$feedback = (info from db);
if (($feedback => 0.5) && ($feedback < 1.5)){
code for copy merging the one star image...
}
else if if (($feedback => 1.5) && ($feedback < 2.5)){
code for copy merging the two star image
}
|
I am sure you get the point now. Good luck and another thing... It might look better to have a star image like youtube has where it has the 3 stars filled in and then two blank stars. I don't know though. I'm sure you will be able to do the making stars bit yourself.
Thanks for that, here's what I've ended up doing:
| Code: |
$rateImage = ImageCreateFromPng("../images/ratings/". $row['rating']. ".png");
imagecopymerge($myImage, $rateImage, 20, 105, 0, 0, 85, 16, 100);
|
But my rating image has alpha transparency - do you know how I can enable it, at the moment the image has a black border around it.
- Garion
imagesavealpha($rateImage, true);
Just add that line after your ImageCreateFromPng line.
| Fire Boar wrote: |
imagesavealpha($rateImage, true);
Just add that line after your ImageCreateFromPng line. |
Thanks for the quick response, but that doesn't seem to want to work for me - Could it have something to do with ImageCreateFromPng?
I haven't actually used this but try this instead:
| Code: |
| imagecopymerge($myImage, $rateImage, 20, 105, 0, 0, 85, 16, 0); |
or try this:
| Code: |
imagealphablending($rateImage, 1);
imagecopy($myImage, $rateImage, 20, 105, 0, 0, 85, 16);
|
Hope something works.
Nothing, sorry
I'm thinking now it could have something to do with the image itself. It shows as transparent in FireFox, but I might need to increase/decrease the alpha channel.
If it's working in Firefox, your script is definitely fine. It's the web browser that is the problem. Go to this page:
http://entropymine.com/jason/testbed/pngtrans/
There are probably some types of PNG format that handle transparancy properly on most last-gen - to - current-gen browsers. I know that Internet Explorer 5 and possibly 6 have trouble with some PNG files.
your best bet is to stick with using ImageCreatFromGIF instead of png, gif has transparency options across all browsers i believe, and IE doesnt support pngs. I had the same problem before, but now i just use gifs for transparent overlaying images.
GIF vs PNG... there are pros and cons to each. PNGs are better, smaller, more modern and generally becoming more standard. Unfortunately, there are still quite a few people using Internet Explorer 5 or below. PNG transparancy is only supported in IE 6 or above (and all of the proper browsers such as Firefox).
GIFs, on the other hand, are slightly bulkier, but are more compatible, because they have been around for longer.
It's your choice, I suppose.